andreypopp / andreypopp/autobind-decorator

Using along with Jest

Offen
#86 4 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
help wanted
Vorherrschende Sprache
JavaScript
Sterne
1.4k
Forks
65
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Example code
```ts
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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.