Skip to content

Instantly share code, notes, and snippets.

@DamianMullins
Last active June 22, 2016 10:50
Show Gist options
  • Save DamianMullins/aa8ee125a80e22d1d6d89a0b85b4cc1b to your computer and use it in GitHub Desktop.
Save DamianMullins/aa8ee125a80e22d1d6d89a0b85b4cc1b to your computer and use it in GitHub Desktop.
Testing with Tape and jsdom global.
import tape from 'tape';
import jsdom from 'jsdom-global';
export function test (description, fn, { html } = {}) {
tape(description, t => {
const cleanup = jsdom(html);
fn(t);
cleanup();
});
}
import { test } from './helpers';
import jsdom from 'jsdom-global';
// init jsdom before all tests
jsdom();
test('truthy', assert => {
assert.ok(true);
assert.end();
});
test('dom', assert => {
assert.equal(window, window);
assert.end();
});
test('paragraph', assert => {
assert.equal(document.querySelector('p'), null, 'should be null');
assert.end();
});
test('document', assert => {
assert.notEqual(document, null, 'should not be null');
assert.end();
});
test('elements', assert => {
const actual = document.querySelector('p');
const expected = 'Hello';
assert.notEqual(actual , null);
assert.equal(actual.innerHTML, expected);
assert.end();
}, { html: '<p>Hello</p>' });
test('elements', assert => {
assert.equal(document.querySelector('p'), null);
assert.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment