diff --git a/index.d.ts b/index.d.ts index a1a8fa595..20c65ca3d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -39,52 +39,90 @@ export type SnapshotOptions = { }; export interface Assertions { - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */ + /** + * Assert that `actual` is + * [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), + * returning Boolean indicating whether the assertion passes. Comes with + * power-assert. + */ assert: AssertAssertion; - /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ + /** + * Assert that `actual` is [deeply + * equal](https://github.com/concordancejs/concordance#comparison-details) to + * `expected`, returning Boolean indicating whether the assertion passes. + */ deepEqual: DeepEqualAssertion; - /** Assert that `actual` is like `expected`. */ + /** + * Assert that `value` is like `selector`, returning Boolean indicating + * whether the assertion passes. + */ like: LikeAssertion; - /** Fail the test. */ + /** Fail the test, always returning `false`. */ fail: FailAssertion; - /** Assert that `actual` is strictly false. */ + /** + * Assert that `actual` is strictly false, returning Boolean indicating + * whether the assertion passes. + */ false: FalseAssertion; - /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */ + /** + * Assert that `actual` is + * [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning + * Boolean whether the assertion passes. + */ falsy: FalsyAssertion; /** * Assert that `actual` is [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) + * as `expected`, returning Boolean indicating whether the assertion passes. */ is: IsAssertion; /** * Assert that `actual` is not [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) + * as `expected`, returning Boolean indicating whether the assertion passes. */ not: NotAssertion; - /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ + /** + * Assert that `actual` is not [deeply + * equal](https://github.com/concordancejs/concordance#comparison-details) to + * `expected`, returning Boolean indicating whether the assertion passes. + */ notDeepEqual: NotDeepEqualAssertion; - /** Assert that `string` does not match the regular expression. */ + /** + * Assert that `string` does not match the regular expression, returning + * Boolean indicating whether the assertion passes. + */ notRegex: NotRegexAssertion; - /** Assert that the function does not throw. */ + /** + * Assert that the function does not throw, returning Boolean indicating + * whether the assertion passes. + */ notThrows: NotThrowsAssertion; - /** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */ + /** + * Assert that the async function does not throw, or that the promise does + * not reject, returning Boolean indicating whether the assertion passes. Must + * be awaited. + */ notThrowsAsync: NotThrowsAsyncAssertion; - /** Count a passing assertion. */ + /** Count a passing assertion, always returning `true`. */ pass: PassAssertion; - /** Assert that `string` matches the regular expression. */ + /** + * Assert that `string` matches the regular expression, returning Boolean + * indicating whether the assertion passes. + */ regex: RegexAssertion; /** @@ -105,56 +143,82 @@ export interface Assertions { */ throwsAsync: ThrowsAsyncAssertion; - /** Assert that `actual` is strictly true. */ + /** + * Assert that `actual` is strictly true, returning Boolean indicating + * whether the assertion passes. + */ true: TrueAssertion; - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */ + /** + * Assert that `actual` is + * [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), + * returning Boolean indicating whether the assertion passes. + */ truthy: TruthyAssertion; } export interface AssertAssertion { - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */ - (actual: any, message?: string): void; + /** + * Assert that `actual` is + * [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), + * returning Boolean indicating whether the assertion passes. Comes with + * power-assert. + */ + (actual: any, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, message?: string): void; } export interface DeepEqualAssertion { - /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ - (actual: ValueType, expected: ValueType, message?: string): void; + /** + * Assert that `actual` is [deeply + * equal](https://github.com/concordancejs/concordance#comparison-details) to + * `expected`, returning Boolean indicating whether the assertion passes. + */ + (actual: ValueType, expected: ValueType, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, expected: any, message?: string): void; } export interface LikeAssertion { - /** Assert that `value` is like `selector`. */ - (value: any, selector: Record, message?: string): void; + /** + * Assert that `value` is like `selector`, returning Boolean indicating + * whether the assertion passes. + */ + (value: any, selector: Record, message?: string): boolean; /** Skip this assertion. */ skip(value: any, selector: any, message?: string): void; } export interface FailAssertion { - /** Fail the test. */ - (message?: string): void; + /** Fail the test, always returning `false`. */ + (message?: string): false; /** Skip this assertion. */ skip(message?: string): void; } export interface FalseAssertion { - /** Assert that `actual` is strictly false. */ - (actual: any, message?: string): void; + /** + * Assert that `actual` is strictly false, returning Boolean indicating + * whether the assertion passes. + */ + (actual: any, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, message?: string): void; } export interface FalsyAssertion { - /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */ - (actual: any, message?: string): void; + /** + * Assert that `actual` is + * [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning + * Boolean whether the assertion passes. + */ + (actual: any, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, message?: string): void; @@ -163,9 +227,10 @@ export interface FalsyAssertion { export interface IsAssertion { /** * Assert that `actual` is [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) + * as `expected`, returning Boolean indicating whether the assertion passes. */ - (actual: ValueType, expected: ValueType, message?: string): void; + (actual: ValueType, expected: ValueType, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, expected: any, message?: string): void; @@ -174,60 +239,80 @@ export interface IsAssertion { export interface NotAssertion { /** * Assert that `actual` is not [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) + * as `expected`, returning Boolean indicating whether the assertion passes. */ - (actual: ValueType, expected: ValueType, message?: string): void; + (actual: ValueType, expected: ValueType, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, expected: any, message?: string): void; } export interface NotDeepEqualAssertion { - /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ - (actual: ValueType, expected: ValueType, message?: string): void; + /** + * Assert that `actual` is not [deeply + * equal](https://github.com/concordancejs/concordance#comparison-details) to + * `expected`, returning Boolean indicating whether the assertion passes. + */ + (actual: ValueType, expected: ValueType, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, expected: any, message?: string): void; } export interface NotRegexAssertion { - /** Assert that `string` does not match the regular expression. */ - (string: string, regex: RegExp, message?: string): void; + /** + * Assert that `string` does not match the regular expression, returning + * Boolean indicating whether the assertion passes. + */ + (string: string, regex: RegExp, message?: string): boolean; /** Skip this assertion. */ skip(string: string, regex: RegExp, message?: string): void; } export interface NotThrowsAssertion { - /** Assert that the function does not throw. */ - (fn: () => any, message?: string): void; + /** + * Assert that the function does not throw, returning Boolean indicating + * whether the assertion passes. + */ + (fn: () => any, message?: string): boolean; /** Skip this assertion. */ skip(fn: () => any, message?: string): void; } export interface NotThrowsAsyncAssertion { - /** Assert that the async function does not throw. You must await the result. */ - (fn: () => PromiseLike, message?: string): Promise; + /** + * Assert that the async function does not throw, returning Boolean + * indicating whether the assertion passes. You must await the result. + */ + (fn: () => PromiseLike, message?: string): Promise; - /** Assert that the promise does not reject. You must await the result. */ - (promise: PromiseLike, message?: string): Promise; + /** + * Assert that the promise does not reject, returning Boolean indicating + * whether the assertion passes. You must await the result. + */ + (promise: PromiseLike, message?: string): Promise; /** Skip this assertion. */ skip(nonThrower: any, message?: string): void; } export interface PassAssertion { - /** Count a passing assertion. */ - (message?: string): void; + /** Count a passing assertion, always returning `true`. */ + (message?: string): true; /** Skip this assertion. */ skip(message?: string): void; } export interface RegexAssertion { - /** Assert that `string` matches the regular expression. */ - (string: string, regex: RegExp, message?: string): void; + /** + * Assert that `string` matches the regular expression, returning Boolean + * indicating whether the assertion passes. + */ + (string: string, regex: RegExp, message?: string): boolean; /** Skip this assertion. */ skip(string: string, regex: RegExp, message?: string): void; @@ -296,16 +381,23 @@ export interface ThrowsAsyncAssertion { } export interface TrueAssertion { - /** Assert that `actual` is strictly true. */ - (actual: any, message?: string): void; + /** + * Assert that `actual` is strictly true, returning Boolean indicating + * whether the assertion passes. + */ + (actual: any, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, message?: string): void; } export interface TruthyAssertion { - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */ - (actual: any, message?: string): void; + /** + * Assert that `actual` is + * [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), + * returning Boolean indicating whether the assertion passes. + */ + (actual: any, message?: string): boolean; /** Skip this assertion. */ skip(actual: any, message?: string): void; @@ -433,7 +525,7 @@ export interface CbExecutionContext extends ExecutionContext< end(error?: any): void; } -export type ImplementationResult = PromiseLike | Subscribable | void; +export type ImplementationResult = PromiseLike | Subscribable | boolean | void; export type Implementation = (t: ExecutionContext) => ImplementationResult; export type CbImplementation = (t: CbExecutionContext) => ImplementationResult; diff --git a/lib/assert.js b/lib/assert.js index 8201ea9fb..c7d69b65c 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -269,6 +269,25 @@ class Assertions { experiments = {}, disableSnapshots = false } = {}) { + // We wrap the original `pass` and `fail` functions in variants that return + // their corresponding Boolean values so we can use them like `return + // fail(...)` in all our internal assertion definitions. + // + // We "override" the original values in this way to ensure that we don't + // accidentally end up calling the original non-Boolean-returning variants + // later in this method, erroneously expecting them to return Booleans. + const originalPass = pass; + pass = (...args) => { + originalPass(...args); + return true; + }; + + const originalFail = fail; + fail = (...args) => { + originalFail(...args); + return false; + }; + const withSkip = assertionFn => { assertionFn.skip = skip; return assertionFn; @@ -306,15 +325,15 @@ class Assertions { }; this.pass = withSkip(() => { - pass(); + return pass(); }); this.fail = withSkip(message => { if (!checkMessage('fail', message)) { - return; + return false; } - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'fail', message: message || 'Test failed via `t.fail()`' })); @@ -322,103 +341,102 @@ class Assertions { this.is = withSkip((actual, expected, message) => { if (!checkMessage('is', message)) { - return; + return false; } if (Object.is(actual, expected)) { - pass(); - } else { - const result = concordance.compare(actual, expected, concordanceOptions); - const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions); - const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions); + return pass(); + } - if (result.pass) { - fail(new AssertionError({ - assertion: 'is', - message, - raw: {actual, expected}, - values: [formatDescriptorWithLabel('Values are deeply equal to each other, but they are not the same:', actualDescriptor)] - })); - } else { - fail(new AssertionError({ - assertion: 'is', - message, - raw: {actual, expected}, - values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)] - })); - } + const result = concordance.compare(actual, expected, concordanceOptions); + const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions); + const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions); + + if (result.pass) { + return fail(new AssertionError({ + assertion: 'is', + message, + raw: {actual, expected}, + values: [formatDescriptorWithLabel('Values are deeply equal to each other, but they are not the same:', actualDescriptor)] + })); } + + return fail(new AssertionError({ + assertion: 'is', + message, + raw: {actual, expected}, + values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)] + })); }); this.not = withSkip((actual, expected, message) => { if (!checkMessage('not', message)) { - return; + return false; } if (Object.is(actual, expected)) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'not', message, raw: {actual, expected}, values: [formatWithLabel('Value is the same as:', actual)] })); - } else { - pass(); } + + return pass(); }); this.deepEqual = withSkip((actual, expected, message) => { if (!checkMessage('deepEqual', message)) { - return; + return false; } const result = concordance.compare(actual, expected, concordanceOptions); if (result.pass) { - pass(); - } else { - const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions); - const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions); - fail(new AssertionError({ - assertion: 'deepEqual', - message, - raw: {actual, expected}, - values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)] - })); + return pass(); } + + const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions); + const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions); + return fail(new AssertionError({ + assertion: 'deepEqual', + message, + raw: {actual, expected}, + values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)] + })); }); this.notDeepEqual = withSkip((actual, expected, message) => { if (!checkMessage('notDeepEqual', message)) { - return; + return false; } const result = concordance.compare(actual, expected, concordanceOptions); if (result.pass) { const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions); - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'notDeepEqual', message, raw: {actual, expected}, values: [formatDescriptorWithLabel('Value is deeply equal:', actualDescriptor)] })); - } else { - pass(); } + + return pass(); }); this.like = withSkip((actual, selector, message) => { if (!checkMessage('like', message)) { - return; + return false; } if (!isLikeSelector(selector)) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'like', improperUsage: true, message: '`t.like()` selector must be a non-empty object', values: [formatWithLabel('Called with:', selector)] })); - return; } let comparable; @@ -426,13 +444,12 @@ class Assertions { comparable = selectComparable(actual, selector); } catch (error) { if (error === CIRCULAR_SELECTOR) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'like', improperUsage: true, message: '`t.like()` selector must not contain circular references', values: [formatWithLabel('Called with:', selector)] })); - return; } throw error; @@ -440,16 +457,16 @@ class Assertions { const result = concordance.compare(comparable, selector, concordanceOptions); if (result.pass) { - pass(); - } else { - const actualDescriptor = result.actual || concordance.describe(comparable, concordanceOptions); - const expectedDescriptor = result.expected || concordance.describe(selector, concordanceOptions); - fail(new AssertionError({ - assertion: 'like', - message, - values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)] - })); + return pass(); } + + const actualDescriptor = result.actual || concordance.describe(comparable, concordanceOptions); + const expectedDescriptor = result.expected || concordance.describe(selector, concordanceOptions); + return fail(new AssertionError({ + assertion: 'like', + message, + values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)] + })); }); this.throws = withSkip((...args) => { @@ -609,47 +626,44 @@ class Assertions { this.notThrows = withSkip((fn, message) => { if (!checkMessage('notThrows', message)) { - return; + return false; } if (typeof fn !== 'function') { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'notThrows', improperUsage: true, message: '`t.notThrows()` must be called with a function', values: [formatWithLabel('Called with:', fn)] })); - return; } try { fn(); } catch (error) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'notThrows', message, actualStack: error.stack, values: [formatWithLabel('Function threw:', error)] })); - return; } - pass(); + return pass(); }); this.notThrowsAsync = withSkip((nonThrower, message) => { if (!checkMessage('notThrowsAsync', message)) { - return Promise.resolve(); + return Promise.resolve(false); } if (typeof nonThrower !== 'function' && !isPromise(nonThrower)) { - fail(new AssertionError({ + return Promise.resolve(fail(new AssertionError({ assertion: 'notThrowsAsync', improperUsage: true, message: '`t.notThrowsAsync()` must be called with a function or promise', values: [formatWithLabel('Called with:', nonThrower)] - })); - return Promise.resolve(); + }))); } const handlePromise = (promise, wasReturned) => { @@ -666,7 +680,8 @@ class Assertions { }); pending(intermediate); // Don't reject the returned promise, even if the assertion fails. - return intermediate.catch(noop); + // eslint-disable-next-line promise/prefer-await-to-then + return intermediate.then(() => true).catch(noop); }; if (isPromise(nonThrower)) { @@ -677,22 +692,20 @@ class Assertions { try { retval = nonThrower(); } catch (error) { - fail(new AssertionError({ + return Promise.resolve(fail(new AssertionError({ assertion: 'notThrowsAsync', message, actualStack: error.stack, values: [formatWithLabel('Function threw:', error)] - })); - return Promise.resolve(); + }))); } if (!isPromise(retval)) { - fail(new AssertionError({ + return Promise.resolve(fail(new AssertionError({ assertion: 'notThrowsAsync', message, values: [formatWithLabel('Function did not return a promise. Use `t.notThrows()` instead:', retval)] - })); - return Promise.resolve(); + }))); } return handlePromise(retval, true); @@ -770,97 +783,95 @@ class Assertions { this.truthy = withSkip((actual, message) => { if (!checkMessage('truthy', message)) { - return; + return false; } if (actual) { - pass(); - } else { - fail(new AssertionError({ - assertion: 'truthy', - message, - operator: '!!', - values: [formatWithLabel('Value is not truthy:', actual)] - })); + return pass(); } + + return fail(new AssertionError({ + assertion: 'truthy', + message, + operator: '!!', + values: [formatWithLabel('Value is not truthy:', actual)] + })); }); this.falsy = withSkip((actual, message) => { if (!checkMessage('falsy', message)) { - return; + return false; } if (actual) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'falsy', message, operator: '!', values: [formatWithLabel('Value is not falsy:', actual)] })); - } else { - pass(); } + + return pass(); }); this.true = withSkip((actual, message) => { if (!checkMessage('true', message)) { - return; + return false; } if (actual === true) { - pass(); - } else { - fail(new AssertionError({ - assertion: 'true', - message, - values: [formatWithLabel('Value is not `true`:', actual)] - })); + return pass(); } + + return fail(new AssertionError({ + assertion: 'true', + message, + values: [formatWithLabel('Value is not `true`:', actual)] + })); }); this.false = withSkip((actual, message) => { if (!checkMessage('false', message)) { - return; + return false; } if (actual === false) { - pass(); - } else { - fail(new AssertionError({ - assertion: 'false', - message, - values: [formatWithLabel('Value is not `false`:', actual)] - })); + return pass(); } + + return fail(new AssertionError({ + assertion: 'false', + message, + values: [formatWithLabel('Value is not `false`:', actual)] + })); }); this.regex = withSkip((string, regex, message) => { if (!checkMessage('regex', message)) { - return; + return false; } if (typeof string !== 'string') { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'regex', improperUsage: true, message: '`t.regex()` must be called with a string', values: [formatWithLabel('Called with:', string)] })); - return; } if (!(regex instanceof RegExp)) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'regex', improperUsage: true, message: '`t.regex()` must be called with a regular expression', values: [formatWithLabel('Called with:', regex)] })); - return; } if (!regex.test(string)) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'regex', message, values: [ @@ -868,39 +879,36 @@ class Assertions { formatWithLabel('Regular expression:', regex) ] })); - return; } - pass(); + return pass(); }); this.notRegex = withSkip((string, regex, message) => { if (!checkMessage('notRegex', message)) { - return; + return false; } if (typeof string !== 'string') { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'notRegex', improperUsage: true, message: '`t.notRegex()` must be called with a string', values: [formatWithLabel('Called with:', string)] })); - return; } if (!(regex instanceof RegExp)) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'notRegex', improperUsage: true, message: '`t.notRegex()` must be called with a regular expression', values: [formatWithLabel('Called with:', regex)] })); - return; } if (regex.test(string)) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'notRegex', message, values: [ @@ -908,29 +916,27 @@ class Assertions { formatWithLabel('Regular expression:', regex) ] })); - return; } - pass(); + return pass(); }); if (powerAssert === undefined) { this.assert = withSkip((actual, message) => { if (!checkMessage('assert', message)) { - return; + return false; } if (!actual) { - fail(new AssertionError({ + return fail(new AssertionError({ assertion: 'assert', message, operator: '!!', values: [formatWithLabel('Value is not truthy:', actual)] })); - return; } - pass(); + return pass(); }); } else { this.assert = withSkip(withPowerAssert( diff --git a/test-tap/assert.js b/test-tap/assert.js index be0f29eb5..a303f0fc5 100644 --- a/test-tap/assert.js +++ b/test-tap/assert.js @@ -11,24 +11,27 @@ const assert = require('../lib/assert'); const snapshotManager = require('../lib/snapshot-manager'); const HelloMessage = require('./fixture/hello-message'); -let lastFailure = null; let lastPassed = false; +let lastFailure = null; const AssertionsBase = class extends assert.Assertions { constructor(overwrites = {}) { super({ pass: () => { lastPassed = true; + return true; }, pending: promise => { promise.then(() => { - lastPassed = true; + return true; }, error => { lastFailure = error; + return false; }); }, fail: error => { lastFailure = error; + return false; }, skip: () => {}, experiments: {}, @@ -39,12 +42,26 @@ const AssertionsBase = class extends assert.Assertions { const assertions = new AssertionsBase(); -function assertFailure(t, subset) { +function assertFailure( + t, + subset, + {actualAssertionReturnValue, expectedAssertionReturnValue} = {} +) { if (!lastFailure) { t.fail('Expected assertion to fail'); return; } + // If given a particular assertion return value to test against, do so. + if (actualAssertionReturnValue !== undefined && expectedAssertionReturnValue !== undefined) { + t.is( + actualAssertionReturnValue, + expectedAssertionReturnValue, + 'Expected the failing assertion to return a particular value' + ); + return; + } + t.is(lastFailure.assertion, subset.assertion); t.is(lastFailure.message, subset.message); t.is(lastFailure.name, 'AssertionError'); @@ -103,7 +120,36 @@ function add(fn) { return gatheringPromise; } +function fails(t, fn) { + lastFailure = null; + const result = fn(); + if (lastFailure && result === false) { + t.pass(); + } else { + t.fail('Expected assertion fail and return false'); + } +} + +function failsReturningArbitraryAssertionReturnValue(t, fn) { + lastFailure = null; + fn(); + if (lastFailure) { + t.pass(); + } else { + t.fail('Expected assertion fail'); + } +} + function failsWith(t, fn, subset) { + lastFailure = null; + const actualAssertionReturnValue = fn(); + assertFailure(t, subset, { + actualAssertionReturnValue, + expectedAssertionReturnValue: false + }); +} + +function failsWithReturningArbitraryAssertionReturnValue(t, fn, subset) { lastFailure = null; fn(); assertFailure(t, subset); @@ -112,40 +158,40 @@ function failsWith(t, fn, subset) { function eventuallyFailsWith(t, fn, subset) { return add(() => { lastFailure = null; - return fn().then(() => { - assertFailure(t, subset); + return fn().then(actualAssertionReturnValue => { + assertFailure(t, subset, { + actualAssertionReturnValue, + expectedAssertionReturnValue: false + }); }); }); } -function fails(t, fn) { - lastFailure = null; - fn(); - if (lastFailure) { - t.pass(); - } else { - t.fail('Expected assertion to fail'); - } -} - -/* Might be useful -function eventuallyFails(t, fn) { +function eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, fn, subset) { return add(() => { lastFailure = null; return fn().then(() => { - if (lastFailure) { - t.pass(); - } else { - t.fail('Expected assertion to fail'); - } + assertFailure(t, subset); }); }); } -*/ function passes(t, fn) { lastPassed = false; lastFailure = null; + + const result = fn(); + if (lastPassed && result === true) { + t.pass(); + } else { + t.ifError(lastFailure, 'Expected assertion to pass and return true'); + } +} + +function passesReturningArbitraryAssertionReturnValue(t, fn) { + lastPassed = false; + lastFailure = null; + fn(); if (lastPassed) { t.pass(); @@ -155,27 +201,41 @@ function passes(t, fn) { } function eventuallyPasses(t, fn) { - return add(() => { + return add(async () => { lastPassed = false; lastFailure = null; - return fn().then(() => { - if (lastPassed) { - t.pass(); - } else { - t.ifError(lastFailure, 'Expected assertion to pass'); - } - }); + + const result = await fn(); + if (lastPassed && result === true) { + t.pass(); + } else { + t.ifError(lastFailure, 'Expected assertion to pass and return true'); + } + }); +} + +function eventuallyPassesReturningArbitraryAssertionReturnValue(t, fn) { + return add(async () => { + lastPassed = false; + lastFailure = null; + + await fn(); + if (lastPassed) { + t.pass(); + } else { + t.ifError(lastFailure, 'Expected assertion to pass'); + } }); } test('.pass()', t => { passes(t, () => { - assertions.pass(); + return assertions.pass(); }); passes(t, () => { const {pass} = assertions; - pass(); + return pass(); }); t.end(); @@ -183,29 +243,28 @@ test('.pass()', t => { test('.fail()', t => { failsWith(t, () => { - assertions.fail(); + return assertions.fail(); }, { assertion: 'fail', message: 'Test failed via `t.fail()`' }); failsWith(t, () => { - assertions.fail('my message'); + return assertions.fail('my message'); }, { assertion: 'fail', message: 'my message' }); failsWith(t, () => { - const {fail} = assertions; - fail(); + return assertions.fail(); }, { assertion: 'fail', message: 'Test failed via `t.fail()`' }); failsWith(t, () => { - assertions.fail(null); + return assertions.fail(null); }, { assertion: 'fail', improperUsage: true, @@ -221,119 +280,118 @@ test('.fail()', t => { test('.is()', t => { passes(t, () => { - assertions.is('foo', 'foo'); + return assertions.is('foo', 'foo'); }); passes(t, () => { - const {is} = assertions; - is('foo', 'foo'); + return assertions.is('foo', 'foo'); }); passes(t, () => { - assertions.is('', ''); + return assertions.is('', ''); }); passes(t, () => { - assertions.is(true, true); + return assertions.is(true, true); }); passes(t, () => { - assertions.is(false, false); + return assertions.is(false, false); }); passes(t, () => { - assertions.is(null, null); + return assertions.is(null, null); }); passes(t, () => { - assertions.is(undefined, undefined); + return assertions.is(undefined, undefined); }); passes(t, () => { - assertions.is(1, 1); + return assertions.is(1, 1); }); passes(t, () => { - assertions.is(0, 0); + return assertions.is(0, 0); }); passes(t, () => { - assertions.is(-0, -0); + return assertions.is(-0, -0); }); passes(t, () => { - assertions.is(Number.NaN, Number.NaN); + return assertions.is(Number.NaN, Number.NaN); }); passes(t, () => { - assertions.is(0 / 0, Number.NaN); + return assertions.is(0 / 0, Number.NaN); }); passes(t, () => { const someRef = {foo: 'bar'}; - assertions.is(someRef, someRef); + return assertions.is(someRef, someRef); }); fails(t, () => { - assertions.is(0, -0); + return assertions.is(0, -0); }); fails(t, () => { - assertions.is(0, false); + return assertions.is(0, false); }); fails(t, () => { - assertions.is('', false); + return assertions.is('', false); }); fails(t, () => { - assertions.is('0', 0); + return assertions.is('0', 0); }); fails(t, () => { - assertions.is('17', 17); + return assertions.is('17', 17); }); fails(t, () => { - assertions.is([1, 2], '1,2'); + return assertions.is([1, 2], '1,2'); }); fails(t, () => { // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins - assertions.is(new String('foo'), 'foo'); + return assertions.is(new String('foo'), 'foo'); }); fails(t, () => { - assertions.is(null, undefined); + return assertions.is(null, undefined); }); fails(t, () => { - assertions.is(null, false); + return assertions.is(null, false); }); fails(t, () => { - assertions.is(undefined, false); + return assertions.is(undefined, false); }); fails(t, () => { // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins - assertions.is(new String('foo'), new String('foo')); + return assertions.is(new String('foo'), new String('foo')); }); fails(t, () => { - assertions.is(0, null); + return assertions.is(0, null); }); fails(t, () => { - assertions.is(0, Number.NaN); + return assertions.is(0, Number.NaN); }); fails(t, () => { - assertions.is('foo', Number.NaN); + return assertions.is('foo', Number.NaN); }); failsWith(t, () => { - assertions.is({foo: 'bar'}, {foo: 'bar'}); + return assertions.is({foo: 'bar'}, {foo: 'bar'}); }, { assertion: 'is', message: '', @@ -346,7 +404,7 @@ test('.is()', t => { }); failsWith(t, () => { - assertions.is('foo', 'bar'); + return assertions.is('foo', 'bar'); }, { assertion: 'is', message: '', @@ -357,7 +415,7 @@ test('.is()', t => { }); failsWith(t, () => { - assertions.is('foo', 42); + return assertions.is('foo', 42); }, { actual: 'foo', assertion: 'is', @@ -369,7 +427,7 @@ test('.is()', t => { }); failsWith(t, () => { - assertions.is('foo', 42, 'my message'); + return assertions.is('foo', 42, 'my message'); }, { assertion: 'is', message: 'my message', @@ -379,7 +437,7 @@ test('.is()', t => { }); failsWith(t, () => { - assertions.is(0, -0, 'my message'); + return assertions.is(0, -0, 'my message'); }, { assertion: 'is', message: 'my message', @@ -389,7 +447,7 @@ test('.is()', t => { }); failsWith(t, () => { - assertions.is(-0, 0, 'my message'); + return assertions.is(-0, 0, 'my message'); }, { assertion: 'is', message: 'my message', @@ -399,7 +457,7 @@ test('.is()', t => { }); failsWith(t, () => { - assertions.is(0, 0, null); + return assertions.is(0, 0, null); }, { assertion: 'is', improperUsage: true, @@ -415,24 +473,23 @@ test('.is()', t => { test('.not()', t => { passes(t, () => { - assertions.not('foo', 'bar'); + return assertions.not('foo', 'bar'); }); passes(t, () => { - const {not} = assertions; - not('foo', 'bar'); + return assertions.not('foo', 'bar'); }); fails(t, () => { - assertions.not(Number.NaN, Number.NaN); + return assertions.not(Number.NaN, Number.NaN); }); fails(t, () => { - assertions.not(0 / 0, Number.NaN); + return assertions.not(0 / 0, Number.NaN); }); failsWith(t, () => { - assertions.not('foo', 'foo'); + return assertions.not('foo', 'foo'); }, { assertion: 'not', message: '', @@ -441,7 +498,7 @@ test('.not()', t => { }); failsWith(t, () => { - assertions.not('foo', 'foo', 'my message'); + return assertions.not('foo', 'foo', 'my message'); }, { assertion: 'not', message: 'my message', @@ -449,7 +506,7 @@ test('.not()', t => { }); failsWith(t, () => { - assertions.not(0, 1, null); + return assertions.not(0, 1, null); }, { assertion: 'not', improperUsage: true, @@ -468,11 +525,11 @@ test('.deepEqual()', t => { // used to test deep object equality fails(t, () => { - assertions.deepEqual({a: false}, {a: 0}); + return assertions.deepEqual({a: false}, {a: 0}); }); passes(t, () => { - assertions.deepEqual({ + return assertions.deepEqual({ a: 'a', b: 'b' }, { @@ -482,12 +539,11 @@ test('.deepEqual()', t => { }); passes(t, () => { - const {deepEqual} = assertions; - deepEqual({a: 'a', b: 'b'}, {b: 'b', a: 'a'}); + return assertions.deepEqual({a: 'a', b: 'b'}, {b: 'b', a: 'a'}); }); passes(t, () => { - assertions.deepEqual({ + return assertions.deepEqual({ a: 'a', b: 'b', c: { @@ -503,17 +559,17 @@ test('.deepEqual()', t => { }); fails(t, () => { - assertions.deepEqual([1, 2, 3], [1, 2, 3, 4]); + return assertions.deepEqual([1, 2, 3], [1, 2, 3, 4]); }); passes(t, () => { - assertions.deepEqual([1, 2, 3], [1, 2, 3]); + return assertions.deepEqual([1, 2, 3], [1, 2, 3]); }); fails(t, () => { const fnA = a => a; const fnB = a => a; - assertions.deepEqual(fnA, fnB); + return assertions.deepEqual(fnA, fnB); }); passes(t, () => { @@ -525,7 +581,7 @@ test('.deepEqual()', t => { const y2 = {x: x2}; x2.y = y2; - assertions.deepEqual(x1, x2); + return assertions.deepEqual(x1, x2); }); passes(t, () => { @@ -536,7 +592,7 @@ test('.deepEqual()', t => { const x = new Foo(1); const y = new Foo(1); - assertions.deepEqual(x, y); + return assertions.deepEqual(x, y); }); fails(t, () => { @@ -551,11 +607,11 @@ test('.deepEqual()', t => { const x = new Foo(1); const y = new Bar(1); - assertions.deepEqual(x, y); + return assertions.deepEqual(x, y); }); fails(t, () => { - assertions.deepEqual({ + return assertions.deepEqual({ a: 'a', b: 'b', c: { @@ -571,73 +627,91 @@ test('.deepEqual()', t => { }); fails(t, () => { - assertions.deepEqual({}, []); + return assertions.deepEqual({}, []); }); fails(t, () => { - assertions.deepEqual({0: 'a', 1: 'b'}, ['a', 'b']); + return assertions.deepEqual({0: 'a', 1: 'b'}, ['a', 'b']); }); fails(t, () => { - assertions.deepEqual({a: 1}, {a: 1, b: undefined}); + return assertions.deepEqual({a: 1}, {a: 1, b: undefined}); }); fails(t, () => { - assertions.deepEqual(new Date('1972-08-01'), null); + return assertions.deepEqual(new Date('1972-08-01'), null); }); fails(t, () => { - assertions.deepEqual(new Date('1972-08-01'), undefined); + return assertions.deepEqual(new Date('1972-08-01'), undefined); }); passes(t, () => { - assertions.deepEqual(new Date('1972-08-01'), new Date('1972-08-01')); + return assertions.deepEqual(new Date('1972-08-01'), new Date('1972-08-01')); }); passes(t, () => { - assertions.deepEqual({x: new Date('1972-08-01')}, {x: new Date('1972-08-01')}); + return assertions.deepEqual({x: new Date('1972-08-01')}, {x: new Date('1972-08-01')}); }); fails(t, () => { - assertions.deepEqual(() => {}, () => {}); + return assertions.deepEqual(() => {}, () => {}); + }); + + passes(t, () => { + return assertions.deepEqual(undefined, undefined); + }); + + passes(t, () => { + return assertions.deepEqual({x: undefined}, {x: undefined}); + }); + + passes(t, () => { + return assertions.deepEqual({x: [undefined]}, {x: [undefined]}); + }); + + passes(t, () => { + return assertions.deepEqual(null, null); }); passes(t, () => { - assertions.deepEqual(undefined, undefined); - assertions.deepEqual({x: undefined}, {x: undefined}); - assertions.deepEqual({x: [undefined]}, {x: [undefined]}); + return assertions.deepEqual({x: null}, {x: null}); }); passes(t, () => { - assertions.deepEqual(null, null); - assertions.deepEqual({x: null}, {x: null}); - assertions.deepEqual({x: [null]}, {x: [null]}); + return assertions.deepEqual({x: [null]}, {x: [null]}); }); passes(t, () => { - assertions.deepEqual(0, 0); - assertions.deepEqual(1, 1); - assertions.deepEqual(3.14, 3.14); + return assertions.deepEqual(0, 0); + }); + + passes(t, () => { + return assertions.deepEqual(1, 1); + }); + + passes(t, () => { + return assertions.deepEqual(3.14, 3.14); }); fails(t, () => { - assertions.deepEqual(0, 1); + return assertions.deepEqual(0, 1); }); fails(t, () => { - assertions.deepEqual(1, -1); + return assertions.deepEqual(1, -1); }); fails(t, () => { - assertions.deepEqual(3.14, 2.72); + return assertions.deepEqual(3.14, 2.72); }); fails(t, () => { - assertions.deepEqual({0: 'a', 1: 'b'}, ['a', 'b']); + return assertions.deepEqual({0: 'a', 1: 'b'}, ['a', 'b']); }); passes(t, () => { - assertions.deepEqual( + return assertions.deepEqual( [ {foo: {z: 100, y: 200, x: 300}}, 'bar', @@ -654,14 +728,14 @@ test('.deepEqual()', t => { }); passes(t, () => { - assertions.deepEqual( + return assertions.deepEqual( {x: {a: 1, b: 2}, y: {c: 3, d: 4}}, {y: {d: 4, c: 3}, x: {b: 2, a: 1}} ); }); passes(t, () => { - assertions.deepEqual( + return assertions.deepEqual( renderer.create(React.createElement(HelloMessage, {name: 'Sindre'})).toJSON(), React.createElement('div', null, 'Hello ', React.createElement('mark', null, 'Sindre')) ); @@ -670,33 +744,33 @@ test('.deepEqual()', t => { // Regression test end here passes(t, () => { - assertions.deepEqual({a: 'a'}, {a: 'a'}); + return assertions.deepEqual({a: 'a'}, {a: 'a'}); }); passes(t, () => { - assertions.deepEqual(['a', 'b'], ['a', 'b']); + return assertions.deepEqual(['a', 'b'], ['a', 'b']); }); fails(t, () => { - assertions.deepEqual({a: 'a'}, {a: 'b'}); + return assertions.deepEqual({a: 'a'}, {a: 'b'}); }); fails(t, () => { - assertions.deepEqual(['a', 'b'], ['a', 'a']); + return assertions.deepEqual(['a', 'b'], ['a', 'a']); }); fails(t, () => { - assertions.deepEqual([['a', 'b'], 'c'], [['a', 'b'], 'd']); + return assertions.deepEqual([['a', 'b'], 'c'], [['a', 'b'], 'd']); }); fails(t, () => { const circular = ['a', 'b']; circular.push(circular); - assertions.deepEqual([circular, 'c'], [circular, 'd']); + return assertions.deepEqual([circular, 'c'], [circular, 'd']); }); failsWith(t, () => { - assertions.deepEqual('foo', 'bar'); + return assertions.deepEqual('foo', 'bar'); }, { assertion: 'deepEqual', message: '', @@ -705,7 +779,7 @@ test('.deepEqual()', t => { }); failsWith(t, () => { - assertions.deepEqual('foo', 42); + return assertions.deepEqual('foo', 42); }, { assertion: 'deepEqual', message: '', @@ -714,7 +788,7 @@ test('.deepEqual()', t => { }); failsWith(t, () => { - assertions.deepEqual('foo', 42, 'my message'); + return assertions.deepEqual('foo', 42, 'my message'); }, { assertion: 'deepEqual', message: 'my message', @@ -722,7 +796,7 @@ test('.deepEqual()', t => { }); failsWith(t, () => { - assertions.deepEqual({}, {}, null); + return assertions.deepEqual({}, {}, null); }, { assertion: 'deepEqual', improperUsage: true, @@ -738,22 +812,21 @@ test('.deepEqual()', t => { test('.notDeepEqual()', t => { passes(t, () => { - assertions.notDeepEqual({a: 'a'}, {a: 'b'}); + return assertions.notDeepEqual({a: 'a'}, {a: 'b'}); }); passes(t, () => { - const {notDeepEqual} = assertions; - notDeepEqual({a: 'a'}, {a: 'b'}); + return assertions.notDeepEqual({a: 'a'}, {a: 'b'}); }); passes(t, () => { - assertions.notDeepEqual(['a', 'b'], ['c', 'd']); + return assertions.notDeepEqual(['a', 'b'], ['c', 'd']); }); const actual = {a: 'a'}; const expected = {a: 'a'}; failsWith(t, () => { - assertions.notDeepEqual(actual, expected); + return assertions.notDeepEqual(actual, expected); }, { actual, assertion: 'notDeepEqual', @@ -764,7 +837,7 @@ test('.notDeepEqual()', t => { }); failsWith(t, () => { - assertions.notDeepEqual(['a', 'b'], ['a', 'b'], 'my message'); + return assertions.notDeepEqual(['a', 'b'], ['a', 'b'], 'my message'); }, { assertion: 'notDeepEqual', message: 'my message', @@ -772,7 +845,7 @@ test('.notDeepEqual()', t => { }); failsWith(t, () => { - assertions.notDeepEqual({}, [], null); + return assertions.notDeepEqual({}, [], null); }, { assertion: 'notDeepEqual', improperUsage: true, @@ -788,11 +861,11 @@ test('.notDeepEqual()', t => { test('.like()', t => { fails(t, () => { - assertions.like({a: false}, {a: 0}); + return assertions.like({a: false}, {a: 0}); }); passes(t, () => { - assertions.like({ + return assertions.like({ a: 'a', b: 'b' }, { @@ -802,12 +875,11 @@ test('.like()', t => { }); passes(t, () => { - const {like} = assertions; - like({a: 'a', b: 'b'}, {b: 'b', a: 'a'}); + return assertions.like({a: 'a', b: 'b'}, {b: 'b', a: 'a'}); }); passes(t, () => { - assertions.like({ + return assertions.like({ a: 'a', b: 'b', c: { @@ -825,11 +897,11 @@ test('.like()', t => { }); fails(t, () => { - assertions.like([1, 2, 3], [1, 2, 3, 4]); + return assertions.like([1, 2, 3], [1, 2, 3, 4]); }); fails(t, () => { - assertions.like({ + return assertions.like({ a: [1, 2, 3] }, { a: [1, 2, 3, 4] @@ -837,7 +909,7 @@ test('.like()', t => { }); passes(t, () => { - assertions.like({ + return assertions.like({ a: [1, 2, 3], x: 'x' }, { @@ -856,19 +928,19 @@ test('.like()', t => { a: 'a' }; - assertions.like(actual, likePattern); + return assertions.like(actual, likePattern); }); fails(t, () => { const fnA = a => a; const fnB = a => a; - assertions.like(fnA, fnB); + return assertions.like(fnA, fnB); }); fails(t, () => { const fnA = a => a; const fnB = a => a; - assertions.like({ + return assertions.like({ fn: fnA }, { fn: fnB @@ -887,59 +959,59 @@ test('.like()', t => { const x = new Foo(1); const y = new Bar(1); - assertions.like(x, y); + return assertions.like(x, y); }); passes(t, () => { - assertions.like({a: 'a'}, {a: 'a'}); + return assertions.like({a: 'a'}, {a: 'a'}); }); passes(t, () => { - assertions.like({a: 'a', b: 'b'}, {a: 'a'}); + return assertions.like({a: 'a', b: 'b'}, {a: 'a'}); }); passes(t, () => { - assertions.like({ab: ['a', 'b']}, {ab: ['a', 'b']}); + return assertions.like({ab: ['a', 'b']}, {ab: ['a', 'b']}); }); passes(t, () => { - assertions.like({ab: ['a', 'b'], c: 'c'}, {ab: ['a', 'b']}); + return assertions.like({ab: ['a', 'b'], c: 'c'}, {ab: ['a', 'b']}); }); fails(t, () => { - assertions.like({a: 'a'}, {a: 'b'}); + return assertions.like({a: 'a'}, {a: 'b'}); }); fails(t, () => { - assertions.like({a: 'a', b: 'b'}, {a: 'b'}); + return assertions.like({a: 'a', b: 'b'}, {a: 'b'}); }); fails(t, () => { - assertions.like({ab: ['a', 'b']}, {ab: ['a', 'a']}); + return assertions.like({ab: ['a', 'b']}, {ab: ['a', 'a']}); }); fails(t, () => { - assertions.like({ab: ['a', 'b'], c: 'c'}, {ab: ['a', 'a']}); + return assertions.like({ab: ['a', 'b'], c: 'c'}, {ab: ['a', 'a']}); }); fails(t, () => { - assertions.like([['a', 'b'], 'c'], [['a', 'b'], 'd']); + return assertions.like([['a', 'b'], 'c'], [['a', 'b'], 'd']); }); fails(t, () => { const circular = ['a', 'b']; circular.push(circular); - assertions.like([circular, 'c'], [circular, 'd']); + return assertions.like([circular, 'c'], [circular, 'd']); }); fails(t, () => { const circular = ['a', 'b']; circular.push(circular); - assertions.like({xc: [circular, 'c']}, {xc: [circular, 'd']}); + return assertions.like({xc: [circular, 'c']}, {xc: [circular, 'd']}); }); failsWith(t, () => { - assertions.like({a: 'a'}, {}); + return assertions.like({a: 'a'}, {}); }, { assertion: 'like', message: '`t.like()` selector must be a non-empty object', @@ -947,7 +1019,7 @@ test('.like()', t => { }); failsWith(t, () => { - assertions.like('foo', 'bar'); + return assertions.like('foo', 'bar'); }, { assertion: 'like', message: '`t.like()` selector must be a non-empty object', @@ -960,7 +1032,7 @@ test('.like()', t => { }; likePattern.circular = likePattern; - assertions.like({}, likePattern); + return assertions.like({}, likePattern); }, { assertion: 'like', message: '`t.like()` selector must not contain circular references', @@ -968,7 +1040,7 @@ test('.like()', t => { }); failsWith(t, () => { - assertions.like({}, {}, null); + return assertions.like({}, {}, null); }, { assertion: 'like', improperUsage: true, @@ -980,7 +1052,7 @@ test('.like()', t => { }); failsWith(t, () => { - assertions.like({a: 'foo', b: 'irrelevant'}, {a: 'bar'}); + return assertions.like({a: 'foo', b: 'irrelevant'}, {a: 'bar'}); }, { assertion: 'like', message: '', @@ -992,7 +1064,7 @@ test('.like()', t => { test('.throws()', gather(t => { // Fails because function doesn't throw. - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}); }, { assertion: 'throws', @@ -1000,7 +1072,7 @@ test('.throws()', gather(t => { values: [{label: 'Function returned:', formatted: /undefined/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { const {throws} = assertions; throws(() => {}); }, { @@ -1011,7 +1083,7 @@ test('.throws()', gather(t => { // Fails because function doesn't throw. Asserts that 'my message' is used // as the assertion message (*not* compared against the error). - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, null, 'my message'); }, { assertion: 'throws', @@ -1020,7 +1092,7 @@ test('.throws()', gather(t => { }); // Fails because the function returned a promise. - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => Promise.resolve()); }, { assertion: 'throws', @@ -1029,7 +1101,7 @@ test('.throws()', gather(t => { }); // Fails because thrown exception is not an error - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { const err = 'foo'; throw err; @@ -1043,14 +1115,14 @@ test('.throws()', gather(t => { }); // Passes because an error is thrown. - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { throw new Error('foo'); }); }); // Passes because the correct error is thrown. - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { const err = new Error('foo'); assertions.throws(() => { throw err; @@ -1058,7 +1130,7 @@ test('.throws()', gather(t => { }); // Fails because the thrown value is not an error - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { const object = {}; assertions.throws(() => { throw object; @@ -1066,7 +1138,7 @@ test('.throws()', gather(t => { }); // Fails because the thrown value is not the right one - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { const err = new Error('foo'); assertions.throws(() => { throw err; @@ -1074,14 +1146,14 @@ test('.throws()', gather(t => { }); // Passes because the correct error is thrown. - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { throw new TypeError(); // eslint-disable-line unicorn/error-message }, {name: 'TypeError'}); }); // Fails because the thrown value is not an error - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { const err = {name: 'Bob'}; throw err; @@ -1089,14 +1161,14 @@ test('.throws()', gather(t => { }); // Fails because the thrown value is not the right one - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { throw new Error('foo'); }, {name: 'TypeError'}); }); // Passes because the correct error is thrown. - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { const err = new TypeError(); err.code = 'ERR_TEST'; @@ -1105,7 +1177,7 @@ test('.throws()', gather(t => { }); // Passes because the correct error is thrown. - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { const err = new TypeError(); err.code = 42; @@ -1114,7 +1186,7 @@ test('.throws()', gather(t => { }); // Fails because the thrown value is not the right one - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { const err = new TypeError(); err.code = 'ERR_NOPE'; @@ -1122,7 +1194,7 @@ test('.throws()', gather(t => { }, {code: 'ERR_TEST'}); }); - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { const err = new TypeError(); err.code = 1; @@ -1131,32 +1203,32 @@ test('.throws()', gather(t => { }); // Regression test for https://github.com/avajs/ava/issues/1676 - fails(t, () => { + failsReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { throw new Error('foo'); }, false); }); // Regression test for https://github.com/avajs/ava/issues/1676 - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { throw new Error('foo'); }, null); }); - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => { throw new Error('foo'); }, undefined); }); - passes(t, async () => { + passesReturningArbitraryAssertionReturnValue(t, async () => { await assertions.throwsAsync(() => { return Promise.reject(new Error('foo')); }, undefined); }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, null, null); }, { assertion: 'throws', @@ -1182,13 +1254,13 @@ test('.throws() returns the thrown error', t => { test('.throwsAsync()', gather(t => { // Fails because the promise is resolved, not rejected. - eventuallyFailsWith(t, () => assertions.throwsAsync(Promise.resolve('foo')), { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(Promise.resolve('foo')), { assertion: 'throwsAsync', message: '', values: [{label: 'Promise resolved with:', formatted: /'foo'/}] }); - eventuallyFailsWith(t, () => { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => { const {throwsAsync} = assertions; return throwsAsync(Promise.resolve('foo')); }, { @@ -1198,27 +1270,27 @@ test('.throwsAsync()', gather(t => { }); // Fails because the promise is resolved with an Error - eventuallyFailsWith(t, () => assertions.throwsAsync(Promise.resolve(new Error())), { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(Promise.resolve(new Error())), { assertion: 'throwsAsync', message: '', values: [{label: 'Promise resolved with:', formatted: /Error/}] }); // Fails because the function returned a promise that resolved, not rejected. - eventuallyFailsWith(t, () => assertions.throwsAsync(() => Promise.resolve('foo')), { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(() => Promise.resolve('foo')), { assertion: 'throwsAsync', message: '', values: [{label: 'Returned promise resolved with:', formatted: /'foo'/}] }); // Passes because the promise was rejected with an error. - eventuallyPasses(t, () => assertions.throwsAsync(Promise.reject(new Error()))); + eventuallyPassesReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(Promise.reject(new Error()))); // Passes because the function returned a promise rejected with an error. - eventuallyPasses(t, () => assertions.throwsAsync(() => Promise.reject(new Error()))); + eventuallyPassesReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(() => Promise.reject(new Error()))); // Fails because the function throws synchronously - eventuallyFailsWith(t, () => assertions.throwsAsync(() => { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(() => { throw new Error('sync'); }, null, 'message'), { assertion: 'throwsAsync', @@ -1229,7 +1301,7 @@ test('.throwsAsync()', gather(t => { }); // Fails because the function did not return a promise - eventuallyFailsWith(t, () => assertions.throwsAsync(() => {}, null, 'message'), { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(() => {}, null, 'message'), { assertion: 'throwsAsync', message: 'message', values: [ @@ -1237,7 +1309,7 @@ test('.throwsAsync()', gather(t => { ] }); - eventuallyFailsWith(t, () => assertions.throwsAsync(Promise.resolve(), null, null), { + eventuallyFailsWithReturningArbitraryAssertionReturnValue(t, () => assertions.throwsAsync(Promise.resolve(), null, null), { assertion: 'throwsAsync', improperUsage: true, message: 'The assertion message must be a string', @@ -1269,7 +1341,7 @@ test('.throwsAsync() returns the rejection reason of a promise returned by the f }); test('.throws() fails if passed a bad value', t => { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws('not a function'); }, { assertion: 'throws', @@ -1281,7 +1353,7 @@ test('.throws() fails if passed a bad value', t => { }); test('.throwsAsync() fails if passed a bad value', t => { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync('not a function'); }, { assertion: 'throwsAsync', @@ -1293,7 +1365,7 @@ test('.throwsAsync() fails if passed a bad value', t => { }); test('.throws() fails if passed a bad expectation', t => { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, true); }, { assertion: 'throws', @@ -1301,7 +1373,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /true/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, 'foo'); }, { assertion: 'throws', @@ -1309,7 +1381,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /foo/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, /baz/); }, { assertion: 'throws', @@ -1317,7 +1389,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /baz/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, class Bar {}); }, { assertion: 'throws', @@ -1325,7 +1397,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /Bar/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, {}); }, { assertion: 'throws', @@ -1333,7 +1405,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /{}/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, []); }, { assertion: 'throws', @@ -1341,7 +1413,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /\[]/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, {code: {}}); }, { assertion: 'throws', @@ -1349,7 +1421,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /code: {}/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, {instanceOf: null}); }, { assertion: 'throws', @@ -1357,7 +1429,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /instanceOf: null/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, {message: null}); }, { assertion: 'throws', @@ -1365,7 +1437,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /message: null/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, {name: null}); }, { assertion: 'throws', @@ -1373,7 +1445,7 @@ test('.throws() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /name: null/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throws(() => {}, {is: {}, message: '', name: '', of() {}, foo: null}); }, { assertion: 'throws', @@ -1385,7 +1457,7 @@ test('.throws() fails if passed a bad expectation', t => { }); test('.throwsAsync() fails if passed a bad expectation', t => { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, true); }, { assertion: 'throwsAsync', @@ -1393,7 +1465,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /true/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, 'foo'); }, { assertion: 'throwsAsync', @@ -1401,7 +1473,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /foo/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, /baz/); }, { assertion: 'throwsAsync', @@ -1409,7 +1481,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /baz/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, class Bar {}); }, { assertion: 'throwsAsync', @@ -1417,7 +1489,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /Bar/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, {}); }, { assertion: 'throwsAsync', @@ -1425,7 +1497,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /{}/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, []); }, { assertion: 'throwsAsync', @@ -1433,7 +1505,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /\[]/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, {code: {}}); }, { assertion: 'throwsAsync', @@ -1441,7 +1513,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /code: {}/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, {instanceOf: null}); }, { assertion: 'throwsAsync', @@ -1449,7 +1521,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /instanceOf: null/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, {message: null}); }, { assertion: 'throwsAsync', @@ -1457,7 +1529,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /message: null/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, {name: null}); }, { assertion: 'throwsAsync', @@ -1465,7 +1537,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { values: [{label: 'Called with:', formatted: /name: null/}] }); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.throwsAsync(() => {}, {is: {}, message: '', name: '', of() {}, foo: null}); }, { assertion: 'throwsAsync', @@ -1479,7 +1551,7 @@ test('.throwsAsync() fails if passed a bad expectation', t => { test('.throws() fails if passed null expectation with disableNullExpectations', t => { const asserter = new AssertionsBase({experiments: {disableNullExpectations: true}}); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { asserter.throws(() => {}, null); }, { assertion: 'throws', @@ -1493,7 +1565,7 @@ test('.throws() fails if passed null expectation with disableNullExpectations', test('.throwsAsync() fails if passed null expectation with disableNullExpectations', t => { const asserter = new AssertionsBase({experiments: {disableNullExpectations: true}}); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { asserter.throwsAsync(() => {}, null); }, { assertion: 'throwsAsync', @@ -1507,17 +1579,16 @@ test('.throwsAsync() fails if passed null expectation with disableNullExpectatio test('.notThrows()', gather(t => { // Passes because the function doesn't throw passes(t, () => { - assertions.notThrows(() => {}); + return assertions.notThrows(() => {}); }); passes(t, () => { - const {notThrows} = assertions; - notThrows(() => {}); + return assertions.notThrows(() => {}); }); // Fails because the function throws. failsWith(t, () => { - assertions.notThrows(() => { + return assertions.notThrows(() => { throw new Error('foo'); }); }, { @@ -1529,7 +1600,7 @@ test('.notThrows()', gather(t => { // Fails because the function throws. Asserts that message is used for the // assertion, not to validate the thrown error. failsWith(t, () => { - assertions.notThrows(() => { + return assertions.notThrows(() => { throw new Error('foo'); }, 'my message'); }, { @@ -1539,7 +1610,7 @@ test('.notThrows()', gather(t => { }); failsWith(t, () => { - assertions.notThrows(() => {}, null); + return assertions.notThrows(() => {}, null); }, { assertion: 'notThrows', improperUsage: true, @@ -1555,11 +1626,6 @@ test('.notThrowsAsync()', gather(t => { // Passes because the promise is resolved eventuallyPasses(t, () => assertions.notThrowsAsync(Promise.resolve())); - eventuallyPasses(t, () => { - const {notThrowsAsync} = assertions; - return notThrowsAsync(Promise.resolve()); - }); - // Fails because the promise is rejected eventuallyFailsWith(t, () => assertions.notThrowsAsync(Promise.reject(new Error())), { assertion: 'notThrowsAsync', @@ -1608,22 +1674,22 @@ test('.notThrowsAsync()', gather(t => { }); })); -test('.notThrowsAsync() returns undefined for a fulfilled promise', t => { +test('.notThrowsAsync() returns true for a fulfilled promise', t => { return assertions.notThrowsAsync(Promise.resolve(Symbol(''))).then(actual => { - t.is(actual, undefined); + t.is(actual, true); }); }); -test('.notThrowsAsync() returns undefined for a fulfilled promise returned by the function', t => { +test('.notThrowsAsync() returns true for a fulfilled promise returned by the function', t => { return assertions.notThrowsAsync(() => { return Promise.resolve(Symbol('')); }).then(actual => { - t.is(actual, undefined); + t.is(actual, true); }); }); test('.notThrows() fails if passed a bad value', t => { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.notThrows('not a function'); }, { assertion: 'notThrows', @@ -1635,7 +1701,7 @@ test('.notThrows() fails if passed a bad value', t => { }); test('.notThrowsAsync() fails if passed a bad value', t => { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.notThrowsAsync('not a function'); }, { assertion: 'notThrowsAsync', @@ -1682,24 +1748,24 @@ test('.snapshot()', t => { { const assertions = setup('passes'); - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot({foo: 'bar'}); }); - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { const {snapshot} = assertions; snapshot({foo: 'bar'}); }); - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot({foo: 'bar'}, {id: 'fixed id'}, 'message not included in snapshot report'); }); - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot(React.createElement(HelloMessage, {name: 'Sindre'})); }); - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot(renderer.create(React.createElement(HelloMessage, {name: 'Sindre'})).toJSON()); }); } @@ -1709,7 +1775,7 @@ test('.snapshot()', t => { if (updating) { assertions.snapshot({foo: 'bar'}); } else { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot({foo: 'not bar'}); }, { assertion: 'snapshot', @@ -1719,7 +1785,7 @@ test('.snapshot()', t => { } } - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { const assertions = setup('fails (fixed id)'); assertions.snapshot({foo: 'not bar'}, {id: 'fixed id'}, 'different message, also not included in snapshot report'); }, { @@ -1733,7 +1799,7 @@ test('.snapshot()', t => { if (updating) { assertions.snapshot({foo: 'bar'}, 'my message'); } else { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot({foo: 'not bar'}, 'my message'); }, { assertion: 'snapshot', @@ -1748,7 +1814,7 @@ test('.snapshot()', t => { if (updating) { assertions.snapshot(renderer.create(React.createElement(HelloMessage, {name: 'Sindre'})).toJSON()); } else { - passes(t, () => { + passesReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot(React.createElement('div', null, 'Hello ', React.createElement('mark', null, 'Sindre'))); }); } @@ -1759,7 +1825,7 @@ test('.snapshot()', t => { if (updating) { assertions.snapshot(renderer.create(React.createElement(HelloMessage, {name: 'Sindre'})).toJSON()); } else { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot(renderer.create(React.createElement(HelloMessage, {name: 'Vadim'})).toJSON()); }, { assertion: 'snapshot', @@ -1774,7 +1840,7 @@ test('.snapshot()', t => { if (updating) { assertions.snapshot(React.createElement(HelloMessage, {name: 'Sindre'})); } else { - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot(React.createElement(HelloMessage, {name: 'Vadim'})); }, { assertion: 'snapshot', @@ -1786,7 +1852,7 @@ test('.snapshot()', t => { { const assertions = setup('bad message'); - failsWith(t, () => { + failsWithReturningArbitraryAssertionReturnValue(t, () => { assertions.snapshot(null, null, null); }, { assertion: 'snapshot', @@ -1805,7 +1871,7 @@ test('.snapshot()', t => { test('.truthy()', t => { failsWith(t, () => { - assertions.truthy(0); + return assertions.truthy(0); }, { assertion: 'truthy', message: '', @@ -1814,7 +1880,7 @@ test('.truthy()', t => { }); failsWith(t, () => { - assertions.truthy(false, 'my message'); + return assertions.truthy(false, 'my message'); }, { assertion: 'truthy', message: 'my message', @@ -1823,18 +1889,23 @@ test('.truthy()', t => { }); passes(t, () => { - assertions.truthy(1); - assertions.truthy(true); + return assertions.truthy(1); }); passes(t, () => { - const {truthy} = assertions; - truthy(1); - truthy(true); + return assertions.truthy(true); + }); + + passes(t, () => { + return assertions.truthy(1); + }); + + passes(t, () => { + return assertions.truthy(true); }); failsWith(t, () => { - assertions.truthy(true, null); + return assertions.truthy(true, null); }, { assertion: 'truthy', improperUsage: true, @@ -1850,7 +1921,7 @@ test('.truthy()', t => { test('.falsy()', t => { failsWith(t, () => { - assertions.falsy(1); + return assertions.falsy(1); }, { assertion: 'falsy', message: '', @@ -1859,7 +1930,7 @@ test('.falsy()', t => { }); failsWith(t, () => { - assertions.falsy(true, 'my message'); + return assertions.falsy(true, 'my message'); }, { assertion: 'falsy', message: 'my message', @@ -1868,18 +1939,23 @@ test('.falsy()', t => { }); passes(t, () => { - assertions.falsy(0); - assertions.falsy(false); + return assertions.falsy(0); + }); + + passes(t, () => { + return assertions.falsy(false); }); passes(t, () => { - const {falsy} = assertions; - falsy(0); - falsy(false); + return assertions.falsy(0); + }); + + passes(t, () => { + return assertions.falsy(false); }); failsWith(t, () => { - assertions.falsy(false, null); + return assertions.falsy(false, null); }, { assertion: 'falsy', improperUsage: true, @@ -1895,7 +1971,7 @@ test('.falsy()', t => { test('.true()', t => { failsWith(t, () => { - assertions.true(1); + return assertions.true(1); }, { assertion: 'true', message: '', @@ -1903,7 +1979,7 @@ test('.true()', t => { }); failsWith(t, () => { - assertions.true(0); + return assertions.true(0); }, { assertion: 'true', message: '', @@ -1911,7 +1987,7 @@ test('.true()', t => { }); failsWith(t, () => { - assertions.true(false); + return assertions.true(false); }, { assertion: 'true', message: '', @@ -1919,7 +1995,7 @@ test('.true()', t => { }); failsWith(t, () => { - assertions.true('foo', 'my message'); + return assertions.true('foo', 'my message'); }, { assertion: 'true', message: 'my message', @@ -1927,7 +2003,7 @@ test('.true()', t => { }); passes(t, () => { - assertions.true(true); + return assertions.true(true); }); passes(t, () => { @@ -1936,7 +2012,7 @@ test('.true()', t => { }); failsWith(t, () => { - assertions.true(true, null); + return assertions.true(true, null); }, { assertion: 'true', improperUsage: true, @@ -1952,7 +2028,7 @@ test('.true()', t => { test('.false()', t => { failsWith(t, () => { - assertions.false(0); + return assertions.false(0); }, { assertion: 'false', message: '', @@ -1960,7 +2036,7 @@ test('.false()', t => { }); failsWith(t, () => { - assertions.false(1); + return assertions.false(1); }, { assertion: 'false', message: '', @@ -1968,7 +2044,7 @@ test('.false()', t => { }); failsWith(t, () => { - assertions.false(true); + return assertions.false(true); }, { assertion: 'false', message: '', @@ -1976,7 +2052,7 @@ test('.false()', t => { }); failsWith(t, () => { - assertions.false('foo', 'my message'); + return assertions.false('foo', 'my message'); }, { assertion: 'false', message: 'my message', @@ -1984,7 +2060,7 @@ test('.false()', t => { }); passes(t, () => { - assertions.false(false); + return assertions.false(false); }); passes(t, () => { @@ -1993,7 +2069,7 @@ test('.false()', t => { }); failsWith(t, () => { - assertions.false(false, null); + return assertions.false(false, null); }, { assertion: 'false', improperUsage: true, @@ -2009,16 +2085,15 @@ test('.false()', t => { test('.regex()', t => { passes(t, () => { - assertions.regex('abc', /^abc$/); + return assertions.regex('abc', /^abc$/); }); passes(t, () => { - const {regex} = assertions; - regex('abc', /^abc$/); + return assertions.regex('abc', /^abc$/); }); failsWith(t, () => { - assertions.regex('foo', /^abc$/); + return assertions.regex('foo', /^abc$/); }, { assertion: 'regex', message: '', @@ -2029,7 +2104,7 @@ test('.regex()', t => { }); failsWith(t, () => { - assertions.regex('foo', /^abc$/, 'my message'); + return assertions.regex('foo', /^abc$/, 'my message'); }, { assertion: 'regex', message: 'my message', @@ -2040,7 +2115,7 @@ test('.regex()', t => { }); failsWith(t, () => { - assertions.regex('foo', /^abc$/, null); + return assertions.regex('foo', /^abc$/, null); }, { assertion: 'regex', improperUsage: true, @@ -2056,7 +2131,7 @@ test('.regex()', t => { test('.regex() fails if passed a bad value', t => { failsWith(t, () => { - assertions.regex(42, /foo/); + return assertions.regex(42, /foo/); }, { assertion: 'regex', improperUsage: true, @@ -2065,7 +2140,7 @@ test('.regex() fails if passed a bad value', t => { }); failsWith(t, () => { - assertions.regex('42', {}); + return assertions.regex('42', {}); }, { assertion: 'regex', message: '`t.regex()` must be called with a regular expression', @@ -2077,16 +2152,15 @@ test('.regex() fails if passed a bad value', t => { test('.notRegex()', t => { passes(t, () => { - assertions.notRegex('abc', /def/); + return assertions.notRegex('abc', /def/); }); passes(t, () => { - const {notRegex} = assertions; - notRegex('abc', /def/); + return assertions.notRegex('abc', /def/); }); failsWith(t, () => { - assertions.notRegex('abc', /abc/); + return assertions.notRegex('abc', /abc/); }, { assertion: 'notRegex', message: '', @@ -2097,7 +2171,7 @@ test('.notRegex()', t => { }); failsWith(t, () => { - assertions.notRegex('abc', /abc/, 'my message'); + return assertions.notRegex('abc', /abc/, 'my message'); }, { assertion: 'notRegex', message: 'my message', @@ -2108,7 +2182,7 @@ test('.notRegex()', t => { }); failsWith(t, () => { - assertions.notRegex('abc', /abc/, null); + return assertions.notRegex('abc', /abc/, null); }, { assertion: 'notRegex', improperUsage: true, @@ -2124,7 +2198,7 @@ test('.notRegex()', t => { test('.notRegex() fails if passed a bad value', t => { failsWith(t, () => { - assertions.notRegex(42, /foo/); + return assertions.notRegex(42, /foo/); }, { assertion: 'notRegex', message: '`t.notRegex()` must be called with a string', @@ -2132,7 +2206,7 @@ test('.notRegex() fails if passed a bad value', t => { }); failsWith(t, () => { - assertions.notRegex('42', {}); + return assertions.notRegex('42', {}); }, { assertion: 'notRegex', message: '`t.notRegex()` must be called with a regular expression', @@ -2144,7 +2218,7 @@ test('.notRegex() fails if passed a bad value', t => { test('.assert()', t => { failsWith(t, () => { - assertions.assert(0); + return assertions.assert(0); }, { assertion: 'assert', message: '', @@ -2153,7 +2227,7 @@ test('.assert()', t => { }); failsWith(t, () => { - assertions.assert(false, 'my message'); + return assertions.assert(false, 'my message'); }, { assertion: 'assert', message: 'my message', @@ -2162,18 +2236,23 @@ test('.assert()', t => { }); passes(t, () => { - assertions.assert(1); - assertions.assert(true); + return assertions.assert(1); + }); + + passes(t, () => { + return assertions.assert(true); + }); + + passes(t, () => { + return assertions.assert(1); }); passes(t, () => { - const {assert} = assertions; - assert(1); - assert(true); + return assertions.assert(true); }); failsWith(t, () => { - assertions.assert(null, null); + return assertions.assert(null, null); }, { assertion: 'assert', improperUsage: true,