Skip to content

Commit

Permalink
Add deprecation assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Jul 30, 2021
1 parent 2d7abba commit 9286e89
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 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`,
});
}
24 changes: 24 additions & 0 deletions 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);
}
}
10 changes: 10 additions & 0 deletions 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.'
);
}
3 changes: 3 additions & 0 deletions addon-test-support/asserts/utils/to-assertion-message.js
@@ -0,0 +1,3 @@
export default function toAssertionMessage(assertion) {
return assertion.message;
}
10 changes: 10 additions & 0 deletions addon-test-support/index.js
Expand Up @@ -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
Expand Down

0 comments on commit 9286e89

Please sign in to comment.