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

Using along with Jest #86

Open
budziam opened this issue Oct 18, 2019 · 4 comments
Open

Using along with Jest #86

budziam opened this issue Oct 18, 2019 · 4 comments

Comments

@budziam
Copy link

budziam commented Oct 18, 2019

Decorating the method with @boundMethod decorator causes that Jest creates incorrect mocked object based on class definition.

Example code

import { boundMethod } from "autobind-decorator";
import jestMock from "jest-mock";

class Abc {
    @boundMethod
    foo() {
        //
    }

    bar() {
        //
    }
}

const Mock = jestMock.generateFromMetadata(jestMock.getMetadata(Abc));
const obj = new Mock();
console.log(Object.keys(obj)); // === ["bar"]

The problem is that the object obj doesn't have the foo method.


The way how to create mocked object instance is taken from this library: https://www.npmjs.com/package/jest-create-mock-instance

@stevemao
Copy link
Collaborator

Does #79 or #57 work for you?

@budziam
Copy link
Author

budziam commented Oct 18, 2019

None of those solve my issue

@cfecherolle
Copy link

cfecherolle commented Jul 9, 2021

Still an issue as of today: when using something like

jest.spyOn(instance, "myHandler");

Where myHandler is a boundMethod in my class component that I'm trying to test, test gives the following error:

TypeError: object[methodName].mockImplementation is not a function

@tibabit
Copy link

tibabit commented Oct 6, 2022

Any updates on this? Has anyone solved this?

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

4 participants