Skip to content

Commit

Permalink
Actually make the assert.verify helper work
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Mar 28, 2018
1 parent f3b6cd4 commit c477d68
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,47 @@ import td from 'testdouble';

QUnit.extend(QUnit.assert, {
verify() {
this.pushResult({
result: true,
message: 'Stub passed verification'
});
try {
td.verify(...arguments);

this.pushResult({
result: true,
message: 'Stub passed verification'
});
} catch ({ message }) {
this.pushResult({
result: false,
message
});
}
},

wasCalled(fxn, expected = 1) {
const meta = td.explain(fxn);
const actual = meta.callCount;
const { callCount: actual } = td.explain(fxn);
const result = actual === expected;

this.pushResult({
result: actual === expected,
result,
actual,
expected,
message: `Should have been called ${expected} times, but was called ${actual}`
message: result
? 'Stub was called the expected number of times'
: `Should have been called ${expected} times, but was called ${actual}`
});
},

wasNotCalled(fxn) {
const meta = td.explain(fxn);
const actual = meta.callCount;
const result = actual === 0;

this.pushResult({
result: actual === 0,
result,
actual,
expected: 0,
message: 'Should not have been called, but it was'
message: result
? 'Stub was not called'
: 'Should not have been called, but it was'
});
}
});
Expand Down

0 comments on commit c477d68

Please sign in to comment.