Skip to content
This repository was archived by the owner on Nov 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions lib/test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -881,14 +881,16 @@ class Test extends Base {
}

beforeEach (fn) {
this.onBeforeEach.push(function (done) {
return fn.call(this, done, this)
// use function so that 'this' can be overridden
this.onBeforeEach.push(function () {
return fn.call(this, this)
})
}

afterEach (fn) {
this.onAfterEach.push(function (done) {
return fn.call(this, done, this)
// use function so that 'this' can be overridden
this.onAfterEach.push(function () {
return fn.call(this, this)
})
}

Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@
"async-hook-domain": "^2.0.1",
"bind-obj-methods": "^2.0.0",
"diff": "^4.0.2",
"function-loop": "^1.0.2",
"function-loop": "^2.0.1",
"minipass": "^3.1.1",
"own-or": "^1.0.0",
"own-or-env": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test-test.js-TAP.test.cjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1498,7 +1498,7 @@ TAP version 13
column: #
file: test/test.js
source: |2
tt.beforeEach(async cb => {
tt.beforeEach(async () => {
throw new Error('poop')
--^
})
Expand All@@ -1520,7 +1520,7 @@ not ok 1 - child # {time}
column: #
file: test/test.js
source: |2
tt.beforeEach(async cb => {
tt.beforeEach(async () => {
throw new Error('poop')
--^
})
Expand Down
14 changes: 5 additions & 9 deletions test/test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -902,22 +902,18 @@ t.test('assertions and weird stuff', t => {
},

'beforeEach afterEach': tt => {
tt.beforeEach(function (cb) {
tt.beforeEach(function () {
console.error('parent be', this.name)
cb()
})
tt.afterEach(function (cb) {
tt.afterEach(function () {
console.error('parent ae', this.name)
cb()
})
tt.test('child', tt => {
tt.beforeEach(function (cb) {
tt.beforeEach(function () {
console.error('child be', this.name)
cb()
})
tt.afterEach(function (cb) {
tt.afterEach(function () {
console.error('child ae', this.name)
cb()
})
tt.test('grandkid', tt => Promise.resolve(console.error('in test')))
tt.end()
Expand All@@ -938,7 +934,7 @@ t.test('assertions and weird stuff', t => {
},

'throw in root beforeEach': tt => {
tt.beforeEach(async cb => {
tt.beforeEach(async () => {
throw new Error('poop')
})
tt.test('child', tt => {
Expand Down