Skip to content

Commit

Permalink
add more assertions; fix others
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Apr 21, 2018
1 parent 241159e commit e9eb05e
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions test/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.mixinMochaAssertions = function (expect) {
});
})
.addAssertion('<RawResult> [not] to have passed', function (expect, result) {
expect(result.code, '[not] to have completed with code', 0);
expect(result.code, '[not] to be', 0);
})
.addAssertion(
'<RawResult|JSONResult> [not] to have completed with [exit] code <number>',
Expand Down Expand Up @@ -77,6 +77,9 @@ exports.mixinMochaAssertions = function (expect) {
failures: expect.it('to be non-empty')
});
})
.addAssertion('<RawResult> [not] to have failed', function (expect, result) {
expect(result.code, '[not] to be greater than', 0);
})
.addAssertion('<JSONResult> [not] to have test count <number>', function (
expect,
result,
Expand Down Expand Up @@ -125,15 +128,34 @@ exports.mixinMochaAssertions = function (expect) {
}
)
.addAssertion(
'<JSONResult> [not] to have failed with error <any>',
function (expect, result, err) {
expect(result, '[not] to have failed').and('[not] to satisfy', {
failures: expect.it('to have an item satisfying', {
err: expect.it('to satisfy', err).or('to satisfy', {message: err})
})
'<JSONResult> [not] to have failed with (error|errors) <any+>',
function (expect, result, errors) {
Array.prototype.slice.call(arguments, 2).forEach(function (error) {
expect(result, '[not] to have failed').and('[not] to satisfy', {
failures: expect.it('to have an item satisfying', {
err: expect
.it('to satisfy', error)
.or('to satisfy', {message: error})
})
});
});
}
)
.addAssertion('<JSONResult> [not] to have (error|errors) <any+>', function (
expect,
result,
errors
) {
Array.prototype.slice.call(arguments, 2).forEach(function (error) {
expect(result, '[not] to satisfy', {
failures: expect.it('to have an item satisfying', {
err: expect
.it('to satisfy', error)
.or('to satisfy', {message: error})
})
});
});
})
.addAssertion(
'<JSONResult> [not] to have passed (test|tests) <string+>',
function (expect, result, titles) {
Expand Down Expand Up @@ -253,5 +275,11 @@ exports.mixinMochaAssertions = function (expect) {
output
) {
expect(result.output, '[not] to satisfy', output);
});
})
.addAssertion(
'<RawResult|JSONResult> to have [exit] code <number>',
function (expect, result, code) {
expect(result.code, 'to be', code);
}
);
};

0 comments on commit e9eb05e

Please sign in to comment.