Hi!
I’m trying to get a better understanding of test, spies, mocks etc by writing my own testing framework but I’ve hit a bit of a brick wall and I’m not sure if I’m missing something simple or need to completely rethink my approach.
I’m trying to replicate the same syntax used in Chai to keep my tests readable:
expect(1).to.equal(1);
but the closest I’ve manage is:
expect(5).to().equal(5);
Here’s my current code for expect:
function expect(exp) {
matchers = {
to: function() {
return matchers;
},
be: function() {
return matchers;
},
equal: function(assertion) {
if (exp === assertion) {
console.log("pass");
return true;
} else {
console.log("fail");
return false;
}
}
};
return matchers;
}
Is there a way to use properties with chaining or do I need to do things differently? I tried browsing Chai’s source code, but it’s really abstracted and jumps around between separate files so much that I just end up getting lost!