Skip to content

Commit

Permalink
Don't use the typeless addAssertion syntax (silences deprecation warn…
Browse files Browse the repository at this point in the history
…ing)
  • Loading branch information
papandreou committed Oct 26, 2019
1 parent fc9620f commit 1869b96
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions test/jsdom-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ const jsdom = require('jsdom');
const expect = unexpected.clone().installPlugin(unexpectedDom);
expect.output.installPlugin(require('magicpen-prism'));

expect.addAssertion('to inspect as [itself]', function(expect, subject, value) {
const originalSubject = subject;
if (typeof subject === 'string') {
subject = new jsdom.JSDOM(
`<!DOCTYPE html><html><head></head><body>${subject}</body></html>`
).window.document.body.firstChild;
}
if (this.flags.itself) {
if (typeof originalSubject === 'string') {
expect(expect.inspect(subject).toString(), 'to equal', originalSubject);
expect.addAssertion(
'<string|DOMNode> to inspect as [itself] <string?>',
function(expect, subject, value) {
const originalSubject = subject;
if (typeof subject === 'string') {
subject = new jsdom.JSDOM(
`<!DOCTYPE html><html><head></head><body>${subject}</body></html>`
).window.document.body.firstChild;
}
if (this.flags.itself) {
if (typeof originalSubject === 'string') {
expect(expect.inspect(subject).toString(), 'to equal', originalSubject);
} else {
throw new Error(
'subject must be given as a string when expected to inspect as itself'
);
}
} else {
throw new Error(
'subject must be given as a string when expected to inspect as itself'
);
expect(expect.inspect(subject).toString(), 'to equal', value);
}
} else {
expect(expect.inspect(subject).toString(), 'to equal', value);
}
});
);

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

0 comments on commit 1869b96

Please sign in to comment.