Expect.js Examples Flashcards
Understand examples of chained Expect.js assertions.
expect(1).to.be.ok();
Expect the 1 to be truthy.
expect({}).to.be.ok();
Expects {} to be truthy.
expect(0).to.not.be.ok();
Expects 0 to be falsy.
expect(1).to.be(1)
Expect 1 === 1
expect(NaN).not.to.equal(NaN);
Expects NaN === NaN
expect({ a: ‘b’ }).to.eql({ a: ‘b’ });
Expects two objects to have the same key values.
expect(5).to.be.a(‘number’);
Expects a value of 5 to be of type ‘Number’
expect([ ‘dog’, ‘cat; ]).to.be.an(‘array’);
Expects value to be of type ‘Array’.
expect([ ‘dog’, ‘cat’ ] ).to.be.an(‘object’);
Expects the type object, using TypeOf Command.
expect(5).to.be.a(Number);
Expects 5 to be a Contructor Number
expect(program.version).to.match(/[0-9]+.[0-9]+.[0-9]+/);
Expects the program.version to match a regex of #.#.#.
expect([1, 2]).to.contain(1);
Expectes to find a value 1 in an array of [ 1, 2 ]
expect(‘hello world’).to.contain(‘world’);
Expects a string to ‘Hello World’ to contain the substring ‘world’.
expect([1,2,3]).to.have.length(3);
Expects an array to have three elements.
expect([]).to.be.empty();
Expects to find an array with no elements.