Without any libraries.
// This note is a summary of work of the Moisty team, week 7 of Makers Academy. Thank you Laura, Daniel, Josue, Josh and Terry.
// Check out the full repo here: https://github.com/lwkchan/moisty.
This file contains the matchers (toEqual
, toInclude
etc.).
const expect = { //vars are accessible everywhere, even when module.
toEqual: function(assert, expect) {
return (assert === expect ? console.log('%c Equality test passed.', 'color: green') : (console.log('%c The test failed as the assertion does not equal the expectation', 'color: red')))
},
toInclude: function(assert, expect) {
return (assert.includes(expect) ? console.log('%c Inclusion test passed', 'color: green') : console.log('%c The test failed as the tested object does not include the expected content', 'color: red' ))
},
toBeTrue: function(assert) {
return (assert === true ? console.log('%c Truth test passed', 'color: green') : console.log("The statement is not truthy. The test failed."))
},
toBeEmpty: function(assert) {
return (assert.length === 0 ? console.log('%c The assertion is empty, test passed.', 'color: green') : console.log('%c The assertion is not empty, test failed.', 'color: red'))
},
}
This file contains definitions of describe
, before
and it blocks
.
var Before = function() {};
Before.prototype.beforeEach = function(callback) {
this.callback = callback;
};
var before = new Before();
(function(exports) {
function describe(string, callback) {
console.log('%c' + string, 'color: darkblue');
callback();
}
function it(string, callback) {
console.log(string);
if (before.callback !== undefined) {
before.callback();
}
callback();
}
exports.describe = describe; // exports it to global scope
exports.it = it; // exports it to global scope
})(this);
This file contains drafts of tests
describe('Notepad', function() {
var notepad;
before.beforeEach(function() {
notepad = new Notepad();
});
it('----> it is empty*', function() {
expect.toBeEmpty(notepad.content);
});
it('----> it is empty**', function() {
notepad.content.push('ehehhehhe');
expect.toBeEmpty(notepad.content);
});
it('----> it is empty***', function() {
expect.toBeEmpty(notepad.content);
});
it('----> it includes hehehe', function() {
notepad.content.push('hehehe');
expect.toInclude(notepad.content, 'hehehe');
});
it('----> it includes hihihi', function() {
notepad.content.push('hehehe');
expect.toInclude(notepad.content, 'hihihi');
});
});