February 2015
Intermediate to advanced
392 pages
8h 12m
English
Now that we have a basic knowledge of Chai, we can continue with our coding. The code we already have in place is clearly not correct, so we need to add another test that forces us to make the code right.
Currently, we are implementing the rule about errors for nonpositive numbers, so we should finish it before continuing. Which test could we add to make our implementation fail? We can try testing the validator with valid numbers. Let's see the result:
describe('A Validator', function() {
it('will return no errors for valid numbers', function() {
expect(validator(3)).to.be.empty;
}); it('will return error.nonpositive for not strictly positive numbers', function() { expect(validator(0)).to.be.deep.equal(['error.nonpositive']); ...Read now
Unlock full access