Skip to content

Instantly share code, notes, and snippets.

@asadm
Last active August 17, 2017 08:34
Show Gist options
  • Save asadm/836283ff9ffd19b6c271fd8cef23c365 to your computer and use it in GitHub Desktop.
Save asadm/836283ff9ffd19b6c271fd8cef23c365 to your computer and use it in GitHub Desktop.
CodePad Mocha Examples (Try them on https://codepad.remoteinterview.io/)
// 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() {});
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