You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Important to note is that I either need to pass on content or options as props or otherwise it will return null.
My initial tests I wrote:
describe(ContentToggle.displayName,()=>{it('renders children if content is passed',()=>{constchildren='FOO';constel=render(<ContentTogglecontent={<span/>}>{children}</ContentToggle>);expect(el).to.have.text(children);});it('renders children if options are passed',()=>{constchildren='FOO';constel=render(<ContentToggleoptions={[]}>{children}</ContentToggle>);expect(el).to.have.text(children);});it('renders nothing if no content or options are passed',()=>{constchildren='FOO';constel=render(<ContentToggle>{children}</ContentToggle>);expect(el).to.not.have.text(children);expect(el).to.be.blank();});});
The first two tests passed, but the third one did not:
1) undefined renders nothing if no content or options are passed:
AssertionError: expected the node in <??? /> to be empty
HTML:
<noscript></noscript>
When I change the 3rd test to use shallow vs render this test passes, or I can write the test as follow:
describe(ContentToggle.displayName,()=>{it('renders nothing if no content or options are passed',()=>{constchildren='FOO';constel=render(<ContentToggle>{children}</ContentToggle>);expect(el).to.not.have.text(children);expect(el.find('noscript')).to.be.blank();});});
I would have expected expect(el).to.be.blank(); to work with both render as with shallow (or mount for that matter), or at least consistent behaviour across all 3.
We can either fix this on chai-enzyme level or in enzyme, what do you guys think?
This is interesting and something I haven't considered yet. React wants every node in the tree to have an actual node in the DOM, so it renders null as <noscript></noscript>. However, cheerio doesn't have any knowledge of this and sees <noscript> as something that is non-empty.
It seems reasonable to have chai-enzyme treat this as a special case, however making cheerio think about things differently would be a lot of work.
I came across an interesting inconsistency, when using enzyme and chai-enzyme.
I'll demonstrate this with code, here's a simplified version of my
ContentToggle
component:Important to note is that I either need to pass on
content
oroptions
as props or otherwise it will returnnull
.My initial tests I wrote:
The first two tests passed, but the third one did not:
When I change the 3rd test to use
shallow
vsrender
this test passes, or I can write the test as follow:I would have expected
expect(el).to.be.blank();
to work with bothrender
as withshallow
(ormount
for that matter), or at least consistent behaviour across all 3.We can either fix this on
chai-enzyme
level or inenzyme
, what do you guys think?/cc @vesln @ljharb @lelandrichardson
The text was updated successfully, but these errors were encountered: