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: API.md
+40-8Lines changed: 40 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -393,7 +393,7 @@ Sets up a test where:
393
393
- the function can return a Promise which either resolves (success) or rejects (fails).
394
394
- all other return value is ignored.
395
395
-`flags` - a set of test utilities described in [Flags](#flags).
396
-
396
+
397
397
```javascript
398
398
lab.experiment('my plan', () => {
399
399
@@ -418,17 +418,49 @@ The `test` function is passed a `flags` object that can be used to create notes
418
418
419
419
#### `context`
420
420
421
-
An object that is passed to `before` and `after` functions in addition to tests themselves. `context` is used to set properties inside the before function that can be used by a test function later. It is meant to reduce module level variables that are set by the `before` / `beforeEach` functions. Tests aren't able to manipulate the context object for other tests.
421
+
An object that is passed to `before` and `after` functions in addition to tests themselves. `context` is used to set properties inside the before function that can be used by a test function later. It is meant to reduce module level variables that are set by the `before` / `beforeEach` functions. The context object is shallow cloned when passed to tests, as well as to child experiments, allowing you to modify it for each experiment individually without conflict through the use of `before`, `beforeEach`, `after` and `afterEach`.
422
422
423
423
```javascript
424
-
lab.before(({ context }) => {
424
+
lab.experiment('my experiment', () => {
425
+
426
+
lab.before(({ context }) => {
427
+
428
+
context.foo='bar';
429
+
})
430
+
431
+
lab.test('contains context', ({ context }) => {
432
+
433
+
expect(context.foo).to.equal('bar');
434
+
});
425
435
426
-
context.foo='bar';
427
-
})
436
+
lab.experiment('a nested experiment', () => {
428
437
429
-
lab.test('contains context', ({ context }) => {
438
+
lab.before(({ context }) => {
430
439
431
-
expect(context.foo).to.equal('bar');
440
+
context.foo='baz';
441
+
});
442
+
443
+
lab.test('has the correct context', ({ context }) => {
444
+
445
+
expect(context.foo).to.equal('baz');
446
+
// since this is a shallow clone, changes will not be carried to
447
+
// future tests or experiments
448
+
context.foo='fizzbuzz';
449
+
});
450
+
451
+
lab.test('receives a clean context', ({ context }) => {
lab.test('maintains the original context', ({ context }) => {
460
+
461
+
expect(context.foo).to.equal('bar');
462
+
});
463
+
});
432
464
});
433
465
```
434
466
@@ -748,7 +780,7 @@ Semantics:
748
780
-`$lab:coverage:push$` copies the current skip state to the top of the stack, and leaves it as the current state as well
749
781
-`$lab:coverage:pop$` replaces the current skip state with the top of the stack, and removes the top of the stack
750
782
- if the stack is empty, `lab` will tell you by throwing the error `"unable to pop coverage bypass stack"`
751
-
783
+
752
784
### Excluding paths from coverage reporting
753
785
754
786
The `--coverage-exclude` argument can be repeated multiple times in order to add multiple paths to exclude. By default the `node_modules` and `test` directories are excluded. If you want to exclude those as well as a directory named `public` you can run lab as follows:
0 commit comments