andreypopp/autobind-decorator

Using along with Jest

開放

#86 建立於 2019年10月18日

 (4 則留言) (2 個反應) (0 位負責人)JavaScript (76 個分叉)batch import
help wanted

倉庫指標

星標
 (1,446 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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

貢獻者指南