We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
this
Take a look at this code:
import { when } from 'jest-when'; class MyName { reGetName( name: string ) { return name; } getName( name: string ) { return this.reGetName( name ); } } it( 'test my name', () => { const component = new MyName(); jest.spyOn( component, 'getName' ); when( component.getName ) .calledWith( 'mark' ) .mockReturnValue( 'mark' ); expect( component.getName( 'mark' ) ).toBe( 'mark' ); // Ok expect( component.getName( 'john' ) ).toBe( 'john' ); // Error } );
Once run this test it gives this error: TypeError: this.reGetName is not a function
TypeError: this.reGetName is not a function
The problem is jest-when change the default implementation of the function.
jest-when
My temporary solution is reset the jest-when implementation by doing something like this:
it( 'test my name 2', () => { const component = new MyName(); jest.spyOn( component, 'getName' ); when( component.getName ) .calledWith( 'mark' ) .mockReturnValue( 'mark' ) .defaultImplementation( MyName.prototype.getName.bind( component ) ); expect( component.getName( 'john' ) ).toBe( 'john' ); // Ok expect( component.getName( 'mark' ) ).toBe( 'mark' ); // Ok } );
To solve this issue jest-when should not change the function's implementation if it's not called with the added arguments.
The text was updated successfully, but these errors were encountered:
Should be fixed by #98
Sorry, something went wrong.
No branches or pull requests
Take a look at this code:
Once run this test it gives this error:
TypeError: this.reGetName is not a function
The problem is
jest-when
change the default implementation of the function.My temporary solution is reset the
jest-when
implementation by doing something like this:To solve this issue
jest-when
should not change the function's implementation if it's not called with the added arguments.The text was updated successfully, but these errors were encountered: