A testing library, designed for front-end javascript.
Add the following tag to the header of your HTML
<script type="text/javascript" src="http://nautdevroome.nl/testing.js"></script>
When you have implemented you JS function like this
function plus(a, b) {
return a + b;
}
You can write a test case for it like this, as long as it ends on Test
function plusTest() {
assertEquals(plus(1, 3), 4);
}
Now you will see the result of your test in the console
plusTest✅ Runtime≈0.400000ms
This will called before each test case
function beforeEach() {
array = [];
console.log('Ready!');
}
This will called after each test case
function afterEach() {
console.log('Im done!');
}
Takes 2 arguments and compares them
function plusTest() {
assertEquals(4, 4);
}
When comparing 2 string and they are not, the fail message will indicate the first character that differs.
When comparing 2 arguments which are aqual, but have a different type, the fail message will show the types of the 2 arguments.
Takes 2 arguments and compares them
function plusTest() {
assertNotEquals(3, 4);
}
Takes 1 arguments checks if it is true
or 1
function plusTest() {
assertTrue(1 == 1);
}
Takes 1 arguments checks if it is false
or 0
function plusTest() {
assertFalse(1 == 2);
}