|
1 | | -import { getDeprecationsForCallback, getDeprecations } from '@ember/test-helpers'; |
| 1 | +import { |
| 2 | + getDeprecationsDuringCallback, |
| 3 | + getDeprecations, |
| 4 | +} from '@ember/test-helpers'; |
2 | 5 | import checkMatcher from './utils/check-matcher'; |
3 | 6 |
|
4 | 7 | export default function expectDeprecation(cb, matcher) { |
5 | | - const test = deprecations => { |
6 | | - const matchedDeprecations = deprecations.filter(deprecation => { |
| 8 | + const test = (deprecations, matcher) => { |
| 9 | + const matchedDeprecations = deprecations.filter((deprecation) => { |
7 | 10 | return checkMatcher(deprecation.message, matcher); |
8 | 11 | }); |
9 | 12 |
|
10 | 13 | this.pushResult({ |
11 | 14 | result: matchedDeprecations.length !== 0, |
12 | 15 | actual: matchedDeprecations, |
13 | 16 | expected: null, |
14 | | - message: 'Expected deprecations during test, but no deprecations were found.' |
| 17 | + message: |
| 18 | + 'Expected deprecations during test, but no deprecations were found.', |
15 | 19 | }); |
16 | | - } |
| 20 | + }; |
17 | 21 |
|
18 | 22 | if (typeof cb !== 'function') { |
19 | | - test(getDeprecations()); |
| 23 | + // cb is not a callback, so we assume it is the matcher |
| 24 | + test(getDeprecations(), cb); |
20 | 25 | } else { |
21 | | - const maybeThenable = getDeprecationsForCallback(cb); |
22 | | - if (maybeThenable !== null && typeof maybeThenable === 'object' && typeof maybeThenable.then === 'function') { |
23 | | - return maybeThenable.then(test); |
| 26 | + const maybeThenable = getDeprecationsDuringCallback(cb); |
| 27 | + if ( |
| 28 | + maybeThenable !== null && |
| 29 | + typeof maybeThenable === 'object' && |
| 30 | + typeof maybeThenable.then === 'function' |
| 31 | + ) { |
| 32 | + return maybeThenable.then((deprecations) => test(deprecations, matcher)); |
24 | 33 | } else { |
25 | | - test(maybeThenable); |
| 34 | + test(maybeThenable, matcher); |
26 | 35 | } |
27 | 36 | } |
28 | | - |
29 | 37 | } |
0 commit comments