jest-decorator
v1.0.1
Published
Write unit tests for jest using typescript class
Downloads
37
Readme
Install
yarn add -D jest-decorator
Example
import { AfterAll, AfterEach, BeforeAll, BeforeEach, Describe, Test } from "jest-decorator";
@Describe("Test jest decorator")
class TestJestDecorator {
private count: number = 0;
@BeforeAll
private beforeAll() {
this.count++;
}
@AfterAll
private afterAll() {
this.count++;
}
@BeforeEach
private beforeEach() {
this.count++;
}
@AfterEach
private afterEach() {
this.count++;
}
@Test("count should be 2")
private test1() {
expect(this.count).toBe(2);
}
@Test("test async function")
private async test2() {
return new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
@Test("count should be 6")
private test3() {
expect(this.count).toBe(6);
}
}