-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
3ffdb5f
to
76beb4e
Compare
76beb4e
to
c393e7e
Compare
…t match for to contain
Pull Request Test Coverage Report for Build 1063
💛 - Coveralls |
Looks promising! Would be nice with a Is it intentional that the assertion passes when the subject itself matches the spec? There's no test that covers it, so I can't really tell. This passes: expect(
parseHtmlNode('<span id="foo"></span>'),
'to contain',
'<span id="foo"></span>'
); I'd argue that it doesn't really contain a match in that case. On the other hand, I don't really know what would be more useful. The support for a RHS string seems broken: expect(parseHtmlNode('<span>hello</span>'), 'to contain', 'hello');
|
@papandreou thanks for the feedback.
It was, but looking at to contain elements matching I can see that it only looks at the descendant elements, so this assertion should behave the same. I'll fix that.
This is a bit more tricky, as you would normally do something like this: expect(
parseHtmlNode('<div><span class="greeting">Hello</span><span class="name">Jane Doe</span></div>'),
'to contain',
'<span class="name">Jane Doe</span>'
); But I think it would be nice if this also worked: expect(
parseHtmlNode('<div><span class="greeting">Hello</span><span class="name">Jane Doe</span></div>'),
'to contain',
'Jane Doe'
); I'll see what I can do. |
I've done some thinking about the semantics and I tend to agree with Andreas - one of the things we know from the past is overly intelligent matching has almost always come to bite us. In this case, it feels right that About the string matching, hmm - I'm not sure. It would be nice it works but again I'm a bit worried that it becomes a bit magic - the behaviouraround what will be found needs to be super clear. By that reasoning the semantics of |
@alexjeffburke and @papandreou I fixed both the cases you pointed out. |
@papandreou about |
Notice that the diff can be improved
ac98309
to
46c3715
Compare
@sunesimonsen I think the removal of the text support is a very good thing - it'll keep the semantics clean and just sidestep any pontetial surprise factor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just some small nitpicks.
|
||
if (typeof spec === 'string') { | ||
throw new Error( | ||
'HTMLElement to contain string: please provide a HTML structure as a string' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for full disclosure -- IMO it'd be fine to support a RHS of a string without HTML tags wrapped around it -- as long as <
etc. are interpreted as HTML rather than text.
We can also add that later, so nbd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@papandreou I'm leaning towards having an explicit
to contain text assertion, that also mirror the current to have text and to satisfy assertions better. What du you think about that idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be a fine addition of its own. I still think <DOMDocument|DOMElement|...> to contain <string>
should behave as I suggest above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think that is what we had, but I saw some weirdness around HTML entities so I just reverted it. Let's see if we can reintroduce it in a later PR.
Fixes: #254