Skip to content

Commit

Permalink
use function instead of => for addAssert
Browse files Browse the repository at this point in the history
Otherwise 'this' is bound improperly when called on the prototype.

Fix #570
  • Loading branch information
isaacs committed Jun 14, 2019
1 parent 300f4e3 commit 8bffe2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class Test extends Base {
if (Test.prototype[name] || this[name])
throw new TypeError('attempt to re-define `' + name + '` assert')

const ASSERT = (...args) => {
const ASSERT = function (...args) {
this.currentAssert = ASSERT
if (typeof args[length] === 'object') {
args[length + 1] = args[length]
Expand Down
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,15 @@ t.test('addAssert', t => {
return t.end()
})

t.test('addAssert on prototype', t => {
function foobar (found, message, extra) {
return this.ok(found, message, extra)
}
Test.prototype.addAssert('foobar', 1, foobar)
t.foobar(true, 'this is fine')
t.end()
})

t.test('spawn', t => {
const okjs = path.resolve(__dirname, '../ok.test.js')
t.teardown(() => fs.unlinkSync(okjs))
Expand Down

0 comments on commit 8bffe2a

Please sign in to comment.