O'Reilly logo

Learning Behavior-driven Development with JavaScript by Enrique Amodeo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Red/Green/Refactor

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']); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required