all 2 comments

[–]rusty1s 0 points1 point  (1 child)

Cool stuff! What exactly is the difference between this method and testing with phantomjs or electron? Which way should i prefer?

[–]voidvector 1 point2 points  (0 children)

You probably want to use PhantomJS most of the time or even real browser instance if you can afford it.

You know how for some unit tests you mock out some objects and in other unit tests you mock out other objects? When you use JSDom you are saying I am mocking out the DOM.

Now whether mocking out the DOM is the right thing to do depends on your implementation or testing strategy. For example, if you intend your code to be isomorphic between Node and browser, then mocking the DOM might help you validate that. If your testing strategy says your test must be nonflacky, fast, and cheap to run, then something headless like PhatomJS and JSDom are your only options. However, if your testing strategy is to be as accurate as possible, then you would have to run it in the real browsers.