Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test & fix lint
  • Loading branch information
atlowChemi committed Apr 16, 2023
commit 013a47d4de692a5f84cf2031dcbb3956bd69091b
3 changes: 1 addition & 2 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ added:
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/47586
description: The `before` function was added to TestContext
description: The `before` function was added to TestContext.
-->

An instance of `TestContext` is passed to each test function in order to
Expand All @@ -1528,7 +1528,6 @@ added: REPLACEME
This function is used to create a hook running before running a suite.
before subtest of the current test.


### `context.beforeEach([fn][, options])`

<!-- YAML
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/output/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const common = require('../../../common');
const assert = require('assert');
const { test, describe, it, before, after, beforeEach, afterEach } = require('node:test');

before((t) => t.diagnostic('before 1 called'));

describe('describe hooks', () => {
const testArr = [];
before(function() {
Expand Down Expand Up @@ -157,3 +159,5 @@ test('t.after() is called if test body throws', (t) => {
});
throw new Error('bye');
});

before((t) => t.diagnostic('before 2 called'));
7 changes: 2 additions & 5 deletions test/fixtures/test-runner/output/hooks.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ not ok 11 - t.afterEach throws
*
*
*
*
...
# Subtest: 2
ok 2 - 2
Expand Down Expand Up @@ -500,7 +499,6 @@ not ok 12 - afterEach when test fails
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
Expand Down Expand Up @@ -541,12 +539,11 @@ not ok 14 - t.after() is called if test body throws
*
*
*
*
*
*
...
# - after() called
1..14
# before 1 called
# before 2 called
# tests 38
# suites 8
# pass 14
Expand Down