Skip to content

Commit 9286e89

Browse files
committed
Add deprecation assertions
1 parent 2d7abba commit 9286e89

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { getDeprecations } from '@ember/test-helpers';
2+
import toAssertionMessage from './utils/to-assertion-message';
3+
4+
export default function deprecationsInclude(expected) {
5+
const deprecations = getDeprecations().map(toAssertionMessage);
6+
this.pushResult({
7+
result: deprecations.indexOf(expected) > -1,
8+
actual: deprecations,
9+
message: `expected to find \`${expected}\` deprecation`,
10+
});
11+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getDeprecationsDuringCallback } from '@ember/test-helpers';
2+
import toAssertionMessage from './utils/to-assertion-message';
3+
4+
export default async function deprecations(callback, expectedDeprecations) {
5+
const maybeThenable = getDeprecationsDuringCallback(callback);
6+
7+
const operation = (deprecations) => {
8+
this.deepEqual(
9+
deprecations.map(toAssertionMessage),
10+
expectedDeprecations,
11+
'Expected deprecations during test.'
12+
);
13+
};
14+
15+
if (
16+
typeof maybeThenable === 'object' &&
17+
maybeThenable !== null &&
18+
typeof maybeThenable.then === 'function'
19+
) {
20+
operation(await maybeThenable);
21+
} else {
22+
operation(maybeThenable);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getDeprecations } from '@ember/test-helpers';
2+
import toAssertionMessage from './utils/to-assertion-message';
3+
4+
export default function noDeprecations() {
5+
this.deepEqual(
6+
getDeprecations().map(toAssertionMessage),
7+
[],
8+
'Expected no deprecations during test.'
9+
);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function toAssertionMessage(assertion) {
2+
return assertion.message;
3+
}

addon-test-support/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ import { installTestNotIsolatedHook } from './test-isolation-validation';
2727

2828
let waitForSettled = true;
2929

30+
import deprecationsInclude from './asserts/deprecations-include';
31+
import deprecations from './asserts/deprecations';
32+
import noDeprecations from './asserts/no-depreactions';
33+
34+
export function setup(assert) {
35+
assert.deprecationsInclude = deprecationsInclude;
36+
assert.deprecations = deprecations;
37+
assert.noDeprecations = noDeprecations;
38+
}
39+
3040
export function setupTest(hooks, _options) {
3141
let options =
3242
_options === undefined

0 commit comments

Comments
 (0)