| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4bece05 commit 4737314
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -537,12 +537,12 @@ class Test extends AsyncResource { | |||
| 537 | 537 | }); | |
| 538 | 538 | ||
| 539 | 539 | try { | |
| 540 | - if (this.parent?.hooks.beforeEach.length > 0) { | ||
| 541 | - await this.parent.runHook('beforeEach', { args, ctx }); | ||
| 542 | - } | ||
| 543 | 540 | if (this.parent?.hooks.before.length > 0) { | |
| 544 | 541 | await this.parent.runHook('before', this.parent.getRunArgs()); | |
| 545 | 542 | } | |
| 543 | + if (this.parent?.hooks.beforeEach.length > 0) { | ||
| 544 | + await this.parent.runHook('beforeEach', { args, ctx }); | ||
| 545 | + } | ||
| 546 | 546 | const stopPromise = stopTest(this.timeout, this.signal); | |
| 547 | 547 | const runArgs = ArrayPrototypeSlice(args); | |
| 548 | 548 | ArrayPrototypeUnshift(runArgs, this.fn, ctx); | |
@@ -574,8 +574,8 @@ class Test extends AsyncResource { | |||
| 574 | 574 | return; | |
| 575 | 575 | } | |
| 576 | 576 | ||
| 577 | - await after(); | ||
| 578 | 577 | await afterEach(); | |
| 578 | + await after(); | ||
| 579 | 579 | this.pass(); | |
| 580 | 580 | } catch (err) { | |
| 581 | 581 | try { await after(); } catch { /* Ignore error. */ } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,19 +99,24 @@ test('test hooks', async (t) => { | |||
| 99 | 99 | await t.test('2', () => testArr.push('2')); | |
| 100 | 100 | ||
| 101 | 101 | await t.test('nested', async (t) => { | |
| 102 | + t.before((t) => testArr.push('nested before ' + t.name)); | ||
| 103 | + t.after((t) => testArr.push('nested after ' + t.name)); | ||
| 102 | 104 | t.beforeEach((t) => testArr.push('nested beforeEach ' + t.name)); | |
| 103 | 105 | t.afterEach((t) => testArr.push('nested afterEach ' + t.name)); | |
| 104 | 106 | await t.test('nested 1', () => testArr.push('nested1')); | |
| 105 | 107 | await t.test('nested 2', () => testArr.push('nested 2')); | |
| 106 | 108 | }); | |
| 107 | 109 | ||
| 108 | 110 | assert.deepStrictEqual(testArr, [ | |
| 109 | - 'beforeEach 1', 'before test hooks', '1', 'afterEach 1', | ||
| 111 | + 'before test hooks', | ||
| 112 | + 'beforeEach 1', '1', 'afterEach 1', | ||
| 110 | 113 | 'beforeEach 2', '2', 'afterEach 2', | |
| 111 | 114 | 'beforeEach nested', | |
| 115 | + 'nested before nested', | ||
| 112 | 116 | 'beforeEach nested 1', 'nested beforeEach nested 1', 'nested1', 'afterEach nested 1', 'nested afterEach nested 1', | |
| 113 | 117 | 'beforeEach nested 2', 'nested beforeEach nested 2', 'nested 2', 'afterEach nested 2', 'nested afterEach nested 2', | |
| 114 | 118 | 'afterEach nested', | |
| 119 | + 'nested after nested', | ||
| 115 | 120 | ]); | |
| 116 | 121 | }); | |
| 117 | 122 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments