Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Unit Testing Behavior Driven Development with Mocha & Chai Test Suites and Test Specs (describe and it)

can someone explain to me expect(true).to.be.ok

I am a little mystified with the function.

//Test suite
describe('Mocha', function () {
    //Test spec (unit test)
    //first argument is a string describing the behaviour
    it('should run our tests using npm', function() {
        //state condition 
        expect(true).to.be.ok;
    });
});

How does it know that we are testing for Mocha? I am still confused about the expect(true).to.be.ok; What does that mean in layman terms!!

2 Answers

http://www.chaijs.com/api/bdd/#method_ok

the expect was imported from chai. the ok method means it would return a truthy value (not: null, NaN, 0, undefined, false, empty string), which would satisfy an if statement.

From chai's mdn

"...you chain together natural language assertions."

The 'natural language' part really helps (it helps me grasp it) to understand how chai works. You write is though you are talking. That's it!

to.be.ok is checking that a value is...ok, that is, if it is a true value (truthy). While it is not a === strict equality, it's used for loose comparisons.