Skip to content

Commit 1869b96

Browse files
committed
Don't use the typeless addAssertion syntax (silences deprecation warning)
1 parent fc9620f commit 1869b96

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

test/jsdom-compatibility.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@ const jsdom = require('jsdom');
55
const expect = unexpected.clone().installPlugin(unexpectedDom);
66
expect.output.installPlugin(require('magicpen-prism'));
77

8-
expect.addAssertion('to inspect as [itself]', function(expect, subject, value) {
9-
const originalSubject = subject;
10-
if (typeof subject === 'string') {
11-
subject = new jsdom.JSDOM(
12-
`<!DOCTYPE html><html><head></head><body>${subject}</body></html>`
13-
).window.document.body.firstChild;
14-
}
15-
if (this.flags.itself) {
16-
if (typeof originalSubject === 'string') {
17-
expect(expect.inspect(subject).toString(), 'to equal', originalSubject);
8+
expect.addAssertion(
9+
'<string|DOMNode> to inspect as [itself] <string?>',
10+
function(expect, subject, value) {
11+
const originalSubject = subject;
12+
if (typeof subject === 'string') {
13+
subject = new jsdom.JSDOM(
14+
`<!DOCTYPE html><html><head></head><body>${subject}</body></html>`
15+
).window.document.body.firstChild;
16+
}
17+
if (this.flags.itself) {
18+
if (typeof originalSubject === 'string') {
19+
expect(expect.inspect(subject).toString(), 'to equal', originalSubject);
20+
} else {
21+
throw new Error(
22+
'subject must be given as a string when expected to inspect as itself'
23+
);
24+
}
1825
} else {
19-
throw new Error(
20-
'subject must be given as a string when expected to inspect as itself'
21-
);
26+
expect(expect.inspect(subject).toString(), 'to equal', value);
2227
}
23-
} else {
24-
expect(expect.inspect(subject).toString(), 'to equal', value);
2528
}
26-
});
29+
);
2730

2831
describe('jsdom bug compatibility', () => {
2932
it('should work without issue #1107 fixed', () => {

0 commit comments

Comments
 (0)