Skip to content

Instantly share code, notes, and snippets.

@DamianMullins
Last active June 22, 2016 10:50
Show Gist options
  • Save DamianMullins/3e4f9ea0cc910d544d98647e437dfc6b to your computer and use it in GitHub Desktop.
Save DamianMullins/3e4f9ea0cc910d544d98647e437dfc6b to your computer and use it in GitHub Desktop.
Testing with Mocha, Chai, and jsdom global.
import { expect } from 'chai';
describe('dom', () => {
before(function () {
this.jsdom = require('jsdom-global')()
})
after(function () {
this.jsdom()
})
it('window', () => {
expect(window).to.equal(window);
});
it('document', () => {
expect(document).to.equal(document);
});
});
describe('elements', () => {
before(function () {
this.jsdom = require('jsdom-global')('<p>Hello</p>')
})
after(function () {
this.jsdom()
})
it('jsdom', () => {
console.log(document.querySelector('.test'));
expect(document.querySelector('p').innerHTML).to.equal('Hello');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment