andreypopp/autobind-decorator

Using along with Jest

Open

#86 opened on Oct 18, 2019

View on GitHub
 (4 comments) (2 reactions) (0 assignees)JavaScript (1,446 stars) (76 forks)batch import
help wanted

Description

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

Contributor guide