How to mock window/document with mocha/chai

There are a few options available to you:

Option 1: Use JSDOM

By adding a DOM to your code, you can unit test much of your client-side code within node.js

Option 2: Use MOCHA on the client

Mocha does run inside the client and you can use separate client-side unit tests. This tends to be my preferred approach as I can test against specific browsers and not a specific JS implantation.

Option 3: Use PhantomJS

PhantomJS allows you to control a headless browser within your testing environment.

Option 4: Headless Chrome

Now that Headless Chrome is out, the PhantomJS maintainer has retired.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)