diff --git a/addon-test-support/asserts/deprecations-include.js b/addon-test-support/asserts/deprecations-include.js new file mode 100644 index 00000000..0e584b12 --- /dev/null +++ b/addon-test-support/asserts/deprecations-include.js @@ -0,0 +1,11 @@ +import { getDeprecations } from '@ember/test-helpers'; +import toAssertionMessage from './utils/to-assertion-message'; + +export default function deprecationsInclude(expected) { + const deprecations = getDeprecations().map(toAssertionMessage); + this.pushResult({ + result: deprecations.indexOf(expected) > -1, + actual: deprecations, + message: `expected to find \`${expected}\` deprecation`, + }); +} diff --git a/addon-test-support/asserts/deprecations.js b/addon-test-support/asserts/deprecations.js new file mode 100644 index 00000000..2b597529 --- /dev/null +++ b/addon-test-support/asserts/deprecations.js @@ -0,0 +1,24 @@ +import { getDeprecationsDuringCallback } from '@ember/test-helpers'; +import toAssertionMessage from './utils/to-assertion-message'; + +export default async function deprecations(callback, expectedDeprecations) { + const maybeThenable = getDeprecationsDuringCallback(callback); + + const operation = (deprecations) => { + this.deepEqual( + deprecations.map(toAssertionMessage), + expectedDeprecations, + 'Expected deprecations during test.' + ); + }; + + if ( + typeof maybeThenable === 'object' && + maybeThenable !== null && + typeof maybeThenable.then === 'function' + ) { + operation(await maybeThenable); + } else { + operation(maybeThenable); + } +} diff --git a/addon-test-support/asserts/no-depreactions.js b/addon-test-support/asserts/no-depreactions.js new file mode 100644 index 00000000..bd72d1bf --- /dev/null +++ b/addon-test-support/asserts/no-depreactions.js @@ -0,0 +1,10 @@ +import { getDeprecations } from '@ember/test-helpers'; +import toAssertionMessage from './utils/to-assertion-message'; + +export default function noDeprecations() { + this.deepEqual( + getDeprecations().map(toAssertionMessage), + [], + 'Expected no deprecations during test.' + ); +} diff --git a/addon-test-support/asserts/utils/to-assertion-message.js b/addon-test-support/asserts/utils/to-assertion-message.js new file mode 100644 index 00000000..b608eb61 --- /dev/null +++ b/addon-test-support/asserts/utils/to-assertion-message.js @@ -0,0 +1,3 @@ +export default function toAssertionMessage(assertion) { + return assertion.message; +} diff --git a/addon-test-support/index.js b/addon-test-support/index.js index db9e50d9..c99488a8 100644 --- a/addon-test-support/index.js +++ b/addon-test-support/index.js @@ -27,6 +27,16 @@ import { installTestNotIsolatedHook } from './test-isolation-validation'; let waitForSettled = true; +import deprecationsInclude from './asserts/deprecations-include'; +import deprecations from './asserts/deprecations'; +import noDeprecations from './asserts/no-depreactions'; + +export function setup(assert) { + assert.deprecationsInclude = deprecationsInclude; + assert.deprecations = deprecations; + assert.noDeprecations = noDeprecations; +} + export function setupTest(hooks, _options) { let options = _options === undefined