Skip to content

Commit c0e2bc8

Browse files
committed
Add deprecation assertions
1 parent 2d7abba commit c0e2bc8

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-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+
};
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 (typeof maybeThenable === 'object' && maybeThenable !== null && typeof maybeThenable.then === 'function') {
16+
operation(await maybeThenable);
17+
} else {
18+
operation(maybeThenable);
19+
}
20+
}
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)