Skip to content

Commit

Permalink
Remove t.ifError() assertion
Browse files Browse the repository at this point in the history
Fixes #1720. `t.falsy()` can be used instead.
  • Loading branch information
kugtong33 authored and novemberborn committed Feb 19, 2018
1 parent 1d9f176 commit e444654
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 40 deletions.
1 change: 0 additions & 1 deletion index.d.ts
Expand Up @@ -22,7 +22,6 @@ export interface Assertions {
fail(message?: string): void;
false(actual: any, message?: string): void;
falsy(actual: any, message?: string): void;
ifError(error: any, message?: string): void;
is<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
not<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
notDeepEqual<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
Expand Down
1 change: 0 additions & 1 deletion index.js.flow
Expand Up @@ -27,7 +27,6 @@ export interface Assertions {
fail(message?: string): void;
false(actual: any, message?: string): void;
falsy(actual: any, message?: string): void;
ifError(error: any, message?: string): void;
is(actual: any, expected: any, message?: string): void;
not(actual: any, expected: any, message?: string): void;
notDeepEqual(actual: any, expected: any, message?: string): void;
Expand Down
12 changes: 0 additions & 12 deletions lib/assert.js
Expand Up @@ -461,18 +461,6 @@ function wrapAssertions(callbacks) {
pass(this);
},

ifError(actual, message) {
if (actual) {
fail(this, new AssertionError({
assertion: 'ifError',
message,
values: [formatWithLabel('Error:', actual)]
}));
} else {
pass(this);
}
},

snapshot(expected, optionsOrMessage, message) {
const options = {};
if (typeof optionsOrMessage === 'string') {
Expand Down
4 changes: 0 additions & 4 deletions readme.md
Expand Up @@ -990,10 +990,6 @@ Assert that `contents` matches `regex`.

Assert that `contents` does not match `regex`.

### `.ifError(error, [message])`

Assert that `error` is falsy.

### `.snapshot(expected, [message])`
### `.snapshot(expected, [options], [message])`

Expand Down
12 changes: 0 additions & 12 deletions test/assert.js
Expand Up @@ -1123,18 +1123,6 @@ test('.notThrows() fails if passed a bad value', t => {
t.end();
});

test('.ifError()', t => {
fails(t, () => {
assertions.ifError(new Error());
});

passes(t, () => {
assertions.ifError(null);
});

t.end();
});

test('.snapshot()', t => {
// Set to `true` to update the snapshot, then run:
// "$(npm bin)"/tap --no-cov -R spec test/assert.js
Expand Down
17 changes: 7 additions & 10 deletions test/test.js
Expand Up @@ -411,7 +411,7 @@ test('fails with thrown non-error object', t => {

test('skipped assertions count towards the plan', t => {
const instance = ava(a => {
a.plan(16);
a.plan(15);
a.pass.skip();
a.fail.skip();
a.is.skip(1, 1);
Expand All @@ -422,7 +422,6 @@ test('skipped assertions count towards the plan', t => {
throw new Error(); // eslint-disable-line unicorn/error-message
});
a.notThrows.skip(() => {});
a.ifError.skip(null);
a.snapshot.skip({});
a.truthy.skip(true);
a.falsy.skip(false);
Expand All @@ -433,14 +432,14 @@ test('skipped assertions count towards the plan', t => {
});
return instance.run().then(result => {
t.is(result.passed, true);
t.is(instance.planCount, 16);
t.is(instance.assertCount, 16);
t.is(instance.planCount, 15);
t.is(instance.assertCount, 15);
});
});

test('assertion.skip() is bound', t => {
const instance = ava(a => {
a.plan(16);
a.plan(15);
(a.pass.skip)();
(a.fail.skip)();
(a.is.skip)(1, 1);
Expand All @@ -451,7 +450,6 @@ test('assertion.skip() is bound', t => {
throw new Error(); // eslint-disable-line unicorn/error-message
});
(a.notThrows.skip)(() => {});
(a.ifError.skip)(null);
(a.snapshot.skip)({});
(a.truthy.skip)(true);
(a.falsy.skip)(false);
Expand All @@ -462,8 +460,8 @@ test('assertion.skip() is bound', t => {
});
return instance.run().then(result => {
t.is(result.passed, true);
t.is(instance.planCount, 16);
t.is(instance.assertCount, 16);
t.is(instance.planCount, 15);
t.is(instance.assertCount, 15);
});
});

Expand Down Expand Up @@ -699,7 +697,7 @@ test('log from tests', t => {
test('assertions are bound', t => {
// This does not test .fail() and .snapshot(). It'll suffice.
return ava(a => {
(a.plan)(14);
(a.plan)(13);
(a.pass)();
(a.is)(1, 1);
(a.not)(1, 2);
Expand All @@ -709,7 +707,6 @@ test('assertions are bound', t => {
throw new Error(); // eslint-disable-line unicorn/error-message
});
(a.notThrows)(() => {});
(a.ifError)(null);
(a.truthy)(true);
(a.falsy)(false);
(a.true)(true);
Expand Down

0 comments on commit e444654

Please sign in to comment.