/mocha_jsdom_coderpad_full.js Secret
Created
September 26, 2016 21:01
Star
You must be signed in to star a gist
A full example of using mocha and jsdom in coderpad.
This file contains 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
const jsdom = require('jsdom'); | |
const Mocha = require('mocha'); | |
const assert = require('assert'); | |
const mocha = new Mocha(); | |
function getContentByClassName(className) { | |
const elements = document.getElementsByClassName(className); | |
if (elements.length === 0) { | |
return ''; | |
} | |
return elements[0].textContent; | |
} | |
const topLevel = this; | |
mocha.suite.emit('pre-require', topLevel, 'solution', mocha); | |
describe('#getContentByClassName', () => { | |
it('should return an empty string if given a non existent class', () => { | |
topLevel.document = jsdom.jsdom('<div class="foo">my content</div>'); | |
assert(getContentByClassName('bar') === ''); | |
}); | |
it('should return the content of a class', () => { | |
topLevel.document = jsdom.jsdom('<div class="foo">my content</div>'); | |
assert(getContentByClassName('foo') === 'my content'); | |
}); | |
}); | |
mocha.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment