Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break sinon.spy(Component.prototype, 'method') #47

Open
noru opened this issue May 7, 2017 · 8 comments
Open

Break sinon.spy(Component.prototype, 'method') #47

noru opened this issue May 7, 2017 · 8 comments

Comments

@noru
Copy link

noru commented May 7, 2017

When using '@autoBind' on a component, then in tests sinon.spy(Component.prototype, 'someMethod') will yield an error:

TypeError: Attempted to wrap undefined property undefined as function
...

Sorry, currently I can't provide more detail, but I'm sure @autobind is the only variable between success/error in tests.

@damianobarbati
Copy link

damianobarbati commented May 11, 2017

+1 same problem with jest


        const instance = component.instance();
        const spy = jest.spyOn(Component.prototype, 'compute');

        component.find('button').simulate('click');
        component.update();

        expect(spy).toBeCalled();

@stevemao
Copy link
Collaborator

stevemao commented Jul 1, 2017

98968ee might fixed this. Please try the latest master branch

@stevemao
Copy link
Collaborator

Please comment if doesn't work for you

@job13er
Copy link

job13er commented Feb 15, 2018

Just in case anyone else happens upon this, I'm fairly certain autobind-decorator is incompatible with sinon (at least with .stub()). It appears sinon uses descriptor.value to check if something is a method or not: https://github.com/sinonjs/sinon/blob/v4.3.0/lib/sinon/stub.js#L30-L34.

As a result, the descriptor.get() that autobind-decorator creates here:
https://github.com/andreypopp/autobind-decorator/blob/v2.1.0/src/index.js#L75-L95
and here:
https://github.com/andreypopp/autobind-decorator/blob/v2.1.0/src/index.js#L83-L92

are always considered a non-function properties.

I didn't dig into sinon.spy as much, but I don't think it was working on @autobind methods either.

@damianobarbati
Copy link

@job13er just declare your class methods as class properties.

@job13er
Copy link

job13er commented Feb 15, 2018

@damianobarbati Thanks. That's always an option, but since I was looking at autobind-decorator, it seems obvious I already have reasons not to want to use class properties, or I would have had no need for autobind-decorator in the first place.

EDIT: Your comment did make me take a second look at why we weren't using class properties in the first place though, so thank you :)

@stevemao
Copy link
Collaborator

@job13er Maybe we should add this to the docs

@stoically
Copy link

Was running into sinon stubs clashing with autobind as well - is there a chance to reopen this issue or is it considered WONTFIX?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants