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
Copy file name to clipboardExpand all lines: readme.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -602,7 +602,7 @@ Remember that AVA runs each test file in its own process. You may not have to cl
602
602
603
603
#### Test context
604
604
605
-
The `.beforeEach()` & `.afterEach()` hooks can share context with the test:
605
+
Hooks can share context with the test:
606
606
607
607
```js
608
608
test.beforeEach(t=> {
@@ -614,10 +614,14 @@ test('context data is foo', t => {
614
614
});
615
615
```
616
616
617
-
The context is not shared between tests, allowing you to set up data in a way where it will not risk leaking to other, subsequent tests. By default `t.context` is an object but you can reassign it:
617
+
Context created in `.before()` hooks is [cloned](https://www.npmjs.com/package/lodash.clone) before it is passed to `.beforeEach()` hooks and / or tests. The `.after()` and `.after.always()` hooks receive the original context value.
618
+
619
+
For `.beforeEach()`, `.afterEach()` and `.afterEach.always()` hooks the context is *not* shared between different tests, allowing you to set up data such that it will not leak to other tests.
620
+
621
+
By default `t.context` is an object but you can reassign it:
618
622
619
623
```js
620
-
test.beforeEach(t=> {
624
+
test.before(t=> {
621
625
t.context='unicorn';
622
626
});
623
627
@@ -626,8 +630,6 @@ test('context is unicorn', t => {
626
630
});
627
631
```
628
632
629
-
Context sharing is *not* available to `.before()` and `.after()` hooks.
630
-
631
633
### Test macros
632
634
633
635
Additional arguments passed to the test declaration will be passed to the test implementation. This is useful for creating reusable test macros.
@@ -827,7 +829,7 @@ Should contain the actual test.
827
829
828
830
Type: `object`
829
831
830
-
The execution object of a particular test. Each test implementation receives a different object. Contains the [assertions](#assertions) as well as `.plan(count)` and `.end()` methods. `t.context` can contain shared state from `.beforeEach()`hooks. `t.title` returns the test's title.
832
+
The execution object of a particular test. Each test implementation receives a different object. Contains the [assertions](#assertions) as well as `.plan(count)` and `.end()` methods. `t.context` can contain shared state from hooks. `t.title` returns the test's title.
0 commit comments