Skip to content

Commit 442c07c

Browse files
authoredJul 27, 2022
fix(jest): Allow being used inside Jest beforeAll
Fix #72
1 parent d3aca19 commit 442c07c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed
 

‎src/environments/jest.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,27 @@ export const getJestEnvironment: TestEnvironmentGetter = () => {
1212
) {
1313
return undefined;
1414
}
15+
let afterEachCallback = () => {};
16+
let beforeEachCallback = () => {};
17+
18+
afterEach(() => {
19+
afterEachCallback();
20+
});
21+
22+
beforeEach(() => {
23+
beforeEachCallback();
24+
});
1525

1626
return {
1727
after(callback: (afterHooks: TestAfterHooks) => void) {
18-
afterEach(() => {
19-
callback({
20-
reportComplaint({ error }) {
21-
throw error;
22-
},
23-
});
28+
afterEachCallback = () => callback({
29+
reportComplaint({ error }) {
30+
throw error;
31+
},
2432
});
2533
},
2634
before: (callback: () => void) => {
27-
beforeEach(callback);
35+
beforeEachCallback = callback
2836
},
2937
filterMethodCalls: ({ methodCalls }) => methodCalls,
3038
};

0 commit comments

Comments
 (0)
Please sign in to comment.