Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<DOMDocument|DOMElement|DOMDocumentFragment> [not] to contain <DOMElement|object> #255

Merged
merged 20 commits into from
Feb 27, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c393e7e
Initial to contain spec spike
sunesimonsen Feb 22, 2019
644401f
Allow tag name mismatches while searching for the right candidate
sunesimonsen Feb 25, 2019
508d11a
Check class names and styles when searching for the best match for to…
sunesimonsen Feb 25, 2019
07e412d
Take regexp's and expect.it's into consideration when finding the bes…
sunesimonsen Feb 25, 2019
f7b02bf
A lot more tests and support for more edge-cases
sunesimonsen Feb 25, 2019
7a7bca9
Ensure the spec options is correct for to contain
sunesimonsen Feb 25, 2019
0667cf6
Make sure that we support the onlyAttributes flag for to contain
sunesimonsen Feb 25, 2019
cab5b93
Document to contain
sunesimonsen Feb 25, 2019
9741b3e
Trying to fix the build
sunesimonsen Feb 25, 2019
67ec4d3
Don't allow to contain to match directly on the subject
sunesimonsen Feb 26, 2019
d586657
Support searching for a plain text string in to contain
sunesimonsen Feb 26, 2019
f7359bf
Test that to contain works on XML documents
sunesimonsen Feb 26, 2019
46c3715
Added not to contain support
sunesimonsen Feb 26, 2019
a1a1a1c
Inspect DOM fragments given as strings as the parsed elements
sunesimonsen Feb 26, 2019
8ea580c
Fixed problem with matching against elements with no children
sunesimonsen Feb 26, 2019
7d4a20f
Revert "Support searching for a plain text string in to contain"
sunesimonsen Feb 26, 2019
4e1e5b9
Simplify conditional
sunesimonsen Feb 27, 2019
7297335
Fixed edge cases around number of matching children
sunesimonsen Feb 27, 2019
681eb67
When scoring text for similarity always trim and lower case
sunesimonsen Feb 27, 2019
1468f1f
Don't consider an attribute with an empty string as absent
sunesimonsen Feb 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed problem with matching against elements with no children
sunesimonsen committed Feb 26, 2019
commit 8ea580c7b5da4cba9d5e3c2cad3ea1eb5dcd56ba
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1625,8 +1625,10 @@ module.exports = {
expect.exportAssertion(
'<DOMDocument|DOMElement|DOMDocumentFragment|DOMNodeList> [not] to contain <DOMElement|object|string>',
(expect, subject, value) => {
const nodes = subject.childNodes || subject;
const isHtml = isInsideHtmlDocument(nodes[0]);
const nodes = subject.childNodes || makeAttachedDOMNodeList(subject);
const isHtml = isInsideHtmlDocument(
subject.childNodes ? subject : nodes
);
const valueType = expect.findTypeOf(value);
let spec = value;

22 changes: 22 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -3167,6 +3167,20 @@ describe('unexpected-dom', () => {
);
});

it('fails when matching against an element with no children', () => {
expect(
() => {
expect(
parseHtmlNode('<div></div>'),
'to contain',
'<span>Jane Doe</span>'
);
},
'to throw',
'expected <div></div> to contain <span>Jane Doe</span>'
);
});

it('should not match directly on the subject', () => {
expect(
() => {
@@ -3351,6 +3365,14 @@ describe('unexpected-dom', () => {
);
});

it('succeeds if the element has no children', () => {
expect(
parseHtmlNode('<div></div>'),
'not to contain',
'<span>Jane Doe</span>'
);
});

it('shows a diff if the given structure is present', () => {
expect(
() => {