Sinon: Uncaught TypeError: Cannot read property 'call' of undefined

Created on 23 Feb 2017  路  6Comments  路  Source: sinonjs/sinon

  • Sinon version : 1.17.7
  • Environment : Node v7.4.0
  • Other libraries you are using: karma/mocha/enzyme, [email protected]

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.

Most helpful comment

馃憤

All 6 comments

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.

馃憤

Was this page helpful?
0 / 5 - 0 ratings