You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Often while writing tests you have some setup work that needs to happen before tests run, and you have some finishing work that needs to happen after tests run. unittest framework provides helper functions to handle this.
4
+
5
+
If you have some work you need to do repeatedly for many tests, you can use `beforeEach` and `afterEach` hooks.
6
+
7
+
::: info
8
+
`beforeEach` and `afterEach` can only work inside describe which will limit its scope
9
+
:::
10
+
11
+
### How to Use
12
+
13
+
```ts
14
+
let setup =0;
15
+
describe("setup", () => {
16
+
// effect for the whole describe including sub-describe
17
+
beforeEach(() => {
18
+
setup=10;
19
+
});
20
+
test("1st", () => {
21
+
expect(setup).equal(10);
22
+
setup=100;
23
+
});
24
+
test("2nd", () => {
25
+
expect(setup).equal(10);
26
+
setup=100;
27
+
});
28
+
test("3nd", () => {
29
+
expect(setup).equal(10);
30
+
});
31
+
});
32
+
```
33
+
34
+
:::info
35
+
If multiple `beforeEach` or `afterEach` is registered, they will be call in order.
Copy file name to clipboardExpand all lines: docs/release-note.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@
6
6
7
7
- Improved the as-test performances.
8
8
- Introduce new features `isolated: false` to significantly reduce test execution time in large projects. ([#73](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/pull/73))
9
+
- Introduce setup and teardown API. ([#77](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework/pull/77))
0 commit comments