These are chat archives for airbnb/enzyme

21st
Jan 2016
Sean Matheson
@ctrlplusb
Jan 21 2016 14:56
hey all, I’ve decided to switch from teaspoon to enzyme today as it looks like enzyme has the community backing. did an npm install and tried to follow the docs, using the describeWithDOM function in my test. this failed saying that the function didn’t exist. I check my packages and noticed I have a v2 RC install of enzyme. are there updated docs available?
oki, figured it out
Sean Matheson
@ctrlplusb
Jan 21 2016 15:01
dropped in my own implementation of jsdom create, lucky I had this util avail due to my teaspoon usage
perhaps an npm install of enzyme shouldn’t auto install the latest rc if the homepage docs aren’t updated to reflect the latest api
may confuse new adopters.
of course, i am deeply greatly for this library though!
constructive criticism
I’m glad that you guys aren’t taking on the responsibility of managing jsdom and sinon yourselves anymore.
That was actually one of the reasons I went for teaspoon originally, I liked their focus on the library itself, and not the external eco system.
Leland Richardson
@lelandrichardson
Jan 21 2016 16:02
Wow. @ctrlplusb the rc is definitely not supposed to get installed! I'll figure out how to fix this today.thanks for letting us know
Leland Richardson
@lelandrichardson
Jan 21 2016 16:55
@ctrlplusb and just FYI, using jsdom on your own (before requiring react or enzyme) will be the recommended approach once we publish 2.0. This will be more compatible with more environments, and more compatible with react itself (which does document caching at require-time)
Jordan Harband
@ljharb
Jan 21 2016 17:16
@ctrlplusb fixed
Sean Matheson
@ctrlplusb
Jan 21 2016 20:36
@lelandrichardson @ljharb ah, great thanks. looks like I have a sneak preview then haha!
@lelandrichardson also, thank you for that insight into React document caching. Do you know if it does this on every require/import of ‘react’? I’ve seen some example tests where people pass through a single instance of React through factory functions into their components. I was struggling to think why, and I guess this could be a reason for it.
Leland Richardson
@lelandrichardson
Jan 21 2016 23:02
@ctrlplusb that could be part of the reason. React has several instances in its source where it uses a cached reference to global.document in order to call document.createElement() and other things. It also checks for the presence of the global document at require time to turn on/off certain flags and handle things differently. Enzyme actually does some things to flip those flags back, but we cant change the variables in the scope of private functions inside react’s source. This has bitten us and is the source of some issues that have been brought up in the repo. As a result, the best thing to do is to ensure that if you are going to use mount(), that you expose a global document before you call require(‘react’) for the first time. If you do this, everything will work swimmingly :)
Sean Matheson
@ctrlplusb
Jan 21 2016 23:03
@lelandrichardson top class tips. thank you kindly sir.
Leland Richardson
@lelandrichardson
Jan 21 2016 23:04
:thumbsup: