Skip to content

Commit

Permalink
Merge pull request #18 from mrloop/assert-expect
Browse files Browse the repository at this point in the history
feat: support assert.expect with reruns
  • Loading branch information
mrloop authored Nov 6, 2024
2 parents 3425b7f + 899a28a commit abdd018
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/assert-result-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ export default class AssertResultHandler {
}

get (target, prop, receiver) {
if (prop === 'pushResult') {
return this.pushResultFn(target)
switch (prop) {
case 'pushResult':
return this.pushResultFn(target)
case 'expect':
return this.expectFn(target)
}
return Reflect.get(target, prop, receiver)
}
Expand All @@ -24,4 +27,10 @@ export default class AssertResultHandler {
}
}
}

expectFn (target) {
return count => {
target.expect(count + target.test.assertions.length)
}
}
}
35 changes: 35 additions & 0 deletions test/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ QUnit.module('default max runs', function () {
})
})

QUnit.module('assert.expect', function () {
const calls = []

retry('should pass with retries', function (assert, currentRun) {
calls.push(['with', currentRun])

assert.expect(3)
assert.ok(true)
if (currentRun === 1) { throw new Error('fail') }
assert.ok(true)
if (currentRun === 2) { throw new Error('fail') }
assert.ok(true)
}, 3)

retry('should pass without retries', function (assert, currentRun) {
calls.push(['without', currentRun])

assert.expect(2)
assert.ok(true)
assert.ok(true)
})

retry.todo('should fail with incorrect count', function (assert, currentRun) {
calls.push(['incorrect', currentRun])

assert.expect(2)
assert.ok(true)
if (currentRun === 1) { throw new Error('fail') }
})

QUnit.test('verify calls', function (assert) {
assert.deepEqual(calls, [['with', 1], ['with', 2], ['with', 3], ['without', 1], ['incorrect', 1], ['incorrect', 2]])
})
})

QUnit.module('retry.todo', function () {
const calls = []

Expand Down

0 comments on commit abdd018

Please sign in to comment.