Last active
August 17, 2017 08:34
-
-
Save asadm/836283ff9ffd19b6c271fd8cef23c365 to your computer and use it in GitHub Desktop.
CodePad Mocha Examples (Try them on https://codepad.remoteinterview.io/)
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
// from https://gist.github.com/kmoroder/174cc7074ff099256620c7605bdb3368 | |
var foo = function() { | |
return "bar"; | |
} | |
var Mocha = require('mocha'); | |
var expect = require('chai').expect; | |
var mocha = new Mocha({ui: 'bdd'}); | |
mocha.suite.emit('pre-require', this, 'solution', mocha); | |
describe("Test suite", function () { | |
it("is working", function () { | |
expect(foo()).to.equal("bar"); | |
}); | |
}); | |
mocha.run(function() {}); |
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
const jsdom = require("jsdom"); | |
const { JSDOM } = 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 dom = new JSDOM(`<div class="foo">my content</div>`); | |
const window = dom.window; | |
const document = dom.window.document; | |
mocha.suite.emit('pre-require', this, 'solution', mocha); | |
describe('#getContentByClassName', () => { | |
it('should return an empty string if given a non existent class', () => { | |
assert(getContentByClassName('bar') === ''); | |
}); | |
it('should return the content of a class', () => { | |
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