What actually happens
Getting
Uncaught TypeError: Cannot read property 'call' of undefined
How to reproduce
const Button = props => (
<button className="btn" onClick={props.onClick} disabled={props.disabled}>
{props.children}
</button>
);
import { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import React from 'react';
import Button from './Button';
describe('Button component', () => {
it('should call onClick handler', () => {
const mockOnClick = sinon.spy();
const wrapper = shallow(<Button onClick={mockOnClick}>Test</Button>);
expect(wrapper.exists()).to.equal(true);
});
});
If i remove the line with the call to sinon.spy(), everything works.
Somehow it is connected to webpack, since it breaks on line
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
in the webpack bundle.
Are you using Sinon from source perhaps?
You might want to try the next version of Sinon, which has much wider support for module systems
npm install sinon@next --save-dev
No, I've installed it with npm. I'll try the beta later today and let you know if the problem persists.
https://github.com/sinonjs/sinon#important-sinon-v1x-does-not-work-with-amdcommonjs-bundlers
Thanks, it worked. Sorry for inconvenience.
馃憤
Most helpful comment
馃憤