Expect.js Examples Flashcards

Understand examples of chained Expect.js assertions.

1
Q

expect(1).to.be.ok();

A

Expect the 1 to be truthy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

expect({}).to.be.ok();

A

Expects {} to be truthy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

expect(0).to.not.be.ok();

A

Expects 0 to be falsy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

expect(1).to.be(1)

A

Expect 1 === 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

expect(NaN).not.to.equal(NaN);

A

Expects NaN === NaN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

expect({ a: ‘b’ }).to.eql({ a: ‘b’ });

A

Expects two objects to have the same key values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

expect(5).to.be.a(‘number’);

A

Expects a value of 5 to be of type ‘Number’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

expect([ ‘dog’, ‘cat; ]).to.be.an(‘array’);

A

Expects value to be of type ‘Array’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

expect([ ‘dog’, ‘cat’ ] ).to.be.an(‘object’);

A

Expects the type object, using TypeOf Command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

expect(5).to.be.a(Number);

A

Expects 5 to be a Contructor Number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

expect(program.version).to.match(/[0-9]+.[0-9]+.[0-9]+/);

A

Expects the program.version to match a regex of #.#.#.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

expect([1, 2]).to.contain(1);

A

Expectes to find a value 1 in an array of [ 1, 2 ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

expect(‘hello world’).to.contain(‘world’);

A

Expects a string to ‘Hello World’ to contain the substring ‘world’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

expect([1,2,3]).to.have.length(3);

A

Expects an array to have three elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

expect([]).to.be.empty();

A

Expects to find an array with no elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

expect({}).to.be.empty();

A

Expects to find an object with no key value pairs.

17
Q

expect({ my: ‘object’ }).to.not.be.empty();`

A

Expects an object to NOT be empty.

18
Q

expect({a: ‘b’}).to.have.property(‘a’);

A

Expects a object to have a key of ‘a’.

19
Q

expect({ a: ‘b’, c: ‘d’ }).to.only.have.keys(‘a’, ‘c’);

A

Expects an object to have only keys ‘a’ and ‘b’.

20
Q

expect({ a: ‘b’, c: ‘d’ }).to.not.only.have.key(‘a’);

A

Expects an object to not only have a key of ‘a’. There must be more keys for this to be true.

21
Q

expect(1).to.be.within(0, Infinity);

A

Expects a number that falls between the range of 1 and Infinity.

22
Q

expect(5).to.be.greaterThan(3);

A

Expects a number (5) to be greater then a number (3).

23
Q

expect(1).to.be.lessThan(3);

A

Expects the number (1) to be less Then the number (3).