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
Add focusable test #65
Conversation
Asked on Reactiflux #testing channel.
Tried this in bce54bb, no luck. I found a way to get at the HTMLInputElement, call |
This approach looks promising. |
bce54bb
to
5b2edbb
Compare
5b2edbb
to
8a73e36
Compare
Should be okay for us since we're using |
JSDOM loads only at the start of the testing, meaning that if a test needs to add event listeners to the window, they cannot since window is already set. I'm thinking that is there a way of adding our own version of window object and test it from that |
Not quite true, the idea of the boilerplate in But you got me thinking about it, and I think I've finally solved it. I did some tests with the following structure: <Foo>
<div>
<input />
</div>
</Foo> I added event listeners to webpackbin (e.g. real browser):
jsdom without enzyme:
jsdom with enzyme:
Something I wanted to try was inspecting the jsdom output, like how we do document.documentElement.outerHTML // documentElement is the <html> tag Called at the top of a test file, this outputs: <html><head></head><body></body></html> So I tried mounting the component with enzyme, and checking the jsdom state: <html><head></head><body></body></html> WTF? Why isn't jsdom's internal structure updating?? I started looking at the enzyme source code, wondering where the call to A little more sleuthing and I find this comment, emphasis mine:
Hmm. What does this mean? Looking at renderIntoDocument: function(instance) {
var div = document.createElement('div');
// None of our tests actually require attaching the container to the
// DOM, and doing so creates a mess that we rely on test isolation to
// clean up, so we're going to stop honoring the name of this method
// (and probably rename it eventually) if no problems arise.
// document.documentElement.appendChild(div);
return ReactDOM.render(instance, div);
}, So the jsdom document we're giving to Enzyme is actually not what we think it is.
Solution: I was thinking about Enzyme's static rendering, but I don't think that would help because it's just basically allowing you to parse a DOM and traverse it with jquery-style selectors, there's no support for events. We still want to use JSDOM, but not enzyme. Just Since we'd be operating on React-rendered HTML, we won't be able to assert on React props like with Enzyme (e.g. we can't do Rabbit holes I went down trying to solve this:
|
5f657b3
to
ab2c73d
Compare
@jasonstats Please revert ab2c73d and rebase this branch. The linting errors are because your local On If we want to revisit it, we should fix it everywhere. |
Figured out a few things: 1) Throwing from inside an event handler is silently caught and ignored. Events were in fact being dispatched. 2) In a vanilla JSDOM implementation, clicking the input bubbles up to the document and window. When React + Enzyme are brought into the mix, the bubbling from input stops working.
ab2c73d
to
b38e47f
Compare
Leaving this on a branch until we can figure out http://stackoverflow.com/questions/36727059/getting-real-dom-nodes-from-enzyme-or-testing-non-react-events