Last active
August 29, 2022 10:06
-
-
Save loldenburg/0be4c0d98f5bf0abc7cdeec012d7a4c6 to your computer and use it in GitHub Desktop.
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
/* Prerequisites: | |
MOCHA JS and CSS and CHAI JS Libraries must have loaded prior to this script | |
*/ | |
/* uncommenting the next row disables the test output to the console, | |
eg if you want to see the results visually in the browser window. | |
For this, a DIV with an id="mocha" must have been inserted into the page. | |
*/ | |
mocha.reporter(mocha.WebKit); | |
// setting up Mocha Reporting UI | |
mocha.setup({ | |
ui: 'bdd', | |
globals: [''] | |
}); // sets UI | |
// telling Mocha to not throw away existing test results | |
mocha.cleanReferencesAfterRun(false); | |
// starting a test "suite" (a collection of tests) | |
describe("My Test Suite", function () { | |
describe("TEST Group 1", function () { // first group of tests | |
it("Is 7 + 4 = 10?", function () { | |
chai.assert.isTrue(7 + 4 === 10); // Chai's assert offers a ton of options to evaluate a statement (https://www.chaijs.com/api/assert/) | |
}); | |
it("Is 7 + 3 at least 9?", function () { | |
chai.assert.isAtLeast(7 + 3, 9); | |
}); | |
}); | |
describe("TEST Group 2", function () { | |
it("Is the Page Context Data Layer an Array?", function () { | |
chai.assert.isArray(utag.data); // this will also fail because it is an Object | |
}); | |
}); | |
describe('Done!', function (done) { | |
it('Ran all tests', function (done) { | |
done(); // <-- this tells mocha the test has ended | |
}); | |
}); | |
}); | |
// tell Mocha to start capturing thrown errors and report them when "done()" is called | |
mocha.run(asyncOnly = false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment