Skip to content

Commit

Permalink
Relocate XML centric "to satisfy" tests into the assertion test file.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Dec 28, 2019
1 parent 941ec30 commit 1a24653
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 65 deletions.
66 changes: 66 additions & 0 deletions test/assertions/to-satisfy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,72 @@ describe('"to satisfy" assertion', () => {
);
});

describe('XMLDocument', () => {
it('should compare XML element names case sensitively', () => {
expect(
() => {
expect(parseXmlDocument('<foO></foO>').firstChild, 'to satisfy', {
name: 'foo'
});
},
'to throw an error satisfying to equal snapshot',
expect.unindent`
expected <foO></foO> to satisfy { name: 'foo' }
<foO // should equal 'foo'
></foO>
`
);
});

it('should compare XML element names case sensitively, even when the owner document lacks a contentType attribute', () => {
expect(
() => {
const document = parseXmlDocument('<foO></foO>');
document.firstChild._ownerDocument = {
toString() {
return '[object XMLDocument]';
}
};
expect(document.firstChild, 'to satisfy', {
name: 'foo'
});
},
'to throw an error satisfying to equal snapshot',
expect.unindent`
expected <foO></foO> to satisfy { name: 'foo' }
<foO // should equal 'foo'
></foO>
`
);
});

describe('with an array as the value', () => {
it('should succeed with a text child', () => {
expect(
parseXmlDocument(
[
'<?xml version="1.0"?>',
'<content>',
' <hello type="greeting">World</hello>',
'</content>'
].join('\n')
),
'queried for first',
'hello',
'to satisfy',
{
attributes: {
type: 'greeting'
},
children: ['World']
}
);
});
});
});

describe('when used with expect.it', () => {
it('succeeds if the given structure is present', () => {
expect(
Expand Down
65 changes: 0 additions & 65 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,31 +773,6 @@ describe('unexpected-dom', () => {
});
}));

describe('to satisfy', () => {
describe('when comparing an array of children', () => {
it('should succeed with a text child', () => {
expect(
[
'<?xml version="1.0"?>',
'<content>',
' <hello type="greeting">World</hello>',
'</content>'
].join('\n'),
'when parsed as XML',
'queried for first',
'hello',
'to satisfy',
{
attributes: {
type: 'greeting'
},
children: ['World']
}
);
});
});
});

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

Expand Down Expand Up @@ -913,44 +888,4 @@ describe('unexpected-dom', () => {
`
);
});

it('should compare XML element names case sensitively', () => {
expect(
() => {
expect(parseXmlDocument('<foO></foO>').firstChild, 'to satisfy', {
name: 'foo'
});
},
'to throw an error satisfying to equal snapshot',
expect.unindent`
expected <foO></foO> to satisfy { name: 'foo' }
<foO // should equal 'foo'
></foO>
`
);
});

it('should compare XML element names case sensitively, even when the owner document lacks a contentType attribute', () => {
expect(
() => {
const document = parseXmlDocument('<foO></foO>');
document.firstChild._ownerDocument = {
toString() {
return '[object XMLDocument]';
}
};
expect(document.firstChild, 'to satisfy', {
name: 'foo'
});
},
'to throw an error satisfying to equal snapshot',
expect.unindent`
expected <foO></foO> to satisfy { name: 'foo' }
<foO // should equal 'foo'
></foO>
`
);
});
});

0 comments on commit 1a24653

Please sign in to comment.