Skip to content

Commit

Permalink
Cleanup "when parsed as XML" tests.
Browse files Browse the repository at this point in the history
Of particular note is the test intended to check that when DOMParser
is available, that it would be used to parse the XML. Actually make
this assertion by checking it was called with the correct arguments.
  • Loading branch information
alexjeffburke committed Dec 28, 2019
1 parent 1a24653 commit 42e341c
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ describe('unexpected-dom', () => {

describe('when parsed as XML', () => {
const xmlSrc = '<?xml version="1.0"?><fooBar yes="sir">foo</fooBar>';
it('should parse a string as a complete XML document', () => {

it('should parse a string as a complete XML document (attributes)', () => {
expect(
xmlSrc,
'when parsed as XML',
Expand All @@ -763,22 +764,33 @@ describe('unexpected-dom', () => {
);
});

it('should provide the parsed document as the fulfillment value when no assertion is provided', () =>
it('should parse a string as a complete XML document (text)', () => {
expect(
'<?xml version="1.0"?><fooBar yes="sir">foo</fooBar>',
'parsed as XML'
).then(document => {
xmlSrc,
'when parsed as XML',
'queried for first',
'fooBar',
'to have text',
'foo'
);
});

it('should provide the parsed document as the fulfillment value when no assertion is provided', () =>
expect(xmlSrc, 'parsed as XML').then(document => {
expect(document, 'queried for first', 'fooBar', 'to have attributes', {
yes: 'sir'
});
}));

describe('when the DOMParser global is available', () => {
const OriginalDOMParser = root.DOMParser;
let seenDomParserArgs;

beforeEach(() => {
seenDomParserArgs = null;
DOMParser = class DOMParser {
parseFromString(str) {
seenDomParserArgs = [str];
return typeof jsdom !== 'undefined'
? new jsdom.JSDOM(str, { contentType: 'text/xml' }).window
.document
Expand All @@ -793,13 +805,16 @@ describe('unexpected-dom', () => {

it('should use DOMParser to parse the document', () => {
expect(
xmlSrc,
'when parsed as XML',
'queried for first',
'fooBar',
'to have text',
'foo'
);
() =>
expect(
xmlSrc,
'when parsed as XML',
expect.it('to be an', 'XMLDocument')
),
'to be fulfilled'
).then(() => {
expect(seenDomParserArgs, 'to equal', [xmlSrc]);
});
});
});
});
Expand Down

0 comments on commit 42e341c

Please sign in to comment.