Last active
June 22, 2016 10:50
-
-
Save DamianMullins/aa8ee125a80e22d1d6d89a0b85b4cc1b to your computer and use it in GitHub Desktop.
Testing with Tape and jsdom global.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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