diff --git a/lib/test.js b/lib/test.js index cab0fd3..fe1b3f0 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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) }) } diff --git a/package-lock.json b/package-lock.json index d2e4abe..e26f033 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,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", @@ -725,9 +725,10 @@ "dev": true }, "node_modules/function-loop": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/function-loop/-/function-loop-1.0.2.tgz", - "integrity": "sha512-Iw4MzMfS3udk/rqxTiDDCllhGwlOrsr50zViTOO/W6lS/9y6B1J0BD2VZzrnWUYBJsl3aeqjgR5v7bWWhZSYbA==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/function-loop/-/function-loop-2.0.1.tgz", + "integrity": "sha512-ktIR+O6i/4h+j/ZhZJNdzeI4i9lEPeEK6UPR2EVyTVBqOwcU3Za9xYKLH64ZR9HmcROyRrOkizNyjjtWJzDDkQ==", + "license": "ISC" }, "node_modules/gensync": { "version": "1.0.0-beta.2", @@ -2477,9 +2478,9 @@ "dev": true }, "function-loop": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/function-loop/-/function-loop-1.0.2.tgz", - "integrity": "sha512-Iw4MzMfS3udk/rqxTiDDCllhGwlOrsr50zViTOO/W6lS/9y6B1J0BD2VZzrnWUYBJsl3aeqjgR5v7bWWhZSYbA==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/function-loop/-/function-loop-2.0.1.tgz", + "integrity": "sha512-ktIR+O6i/4h+j/ZhZJNdzeI4i9lEPeEK6UPR2EVyTVBqOwcU3Za9xYKLH64ZR9HmcROyRrOkizNyjjtWJzDDkQ==" }, "gensync": { "version": "1.0.0-beta.2", diff --git a/package.json b/package.json index 36994f2..5a5a42a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tap-snapshots/test-test.js-TAP.test.cjs b/tap-snapshots/test-test.js-TAP.test.cjs index 644f428..8591b77 100644 --- a/tap-snapshots/test-test.js-TAP.test.cjs +++ b/tap-snapshots/test-test.js-TAP.test.cjs @@ -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') --^ }) @@ -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') --^ }) diff --git a/test/test.js b/test/test.js index 1ac8896..3a2d24b 100644 --- a/test/test.js +++ b/test/test.js @@ -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() @@ -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 => {