Should.js Assertions Flashcards

Chainable assertions for Should.js Testing Framework. https://github.com/visionmedia/should.js (54 cards)

1
Q

.ok

A

Asserts true

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

.true

A

Assert === true:

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

.false

A

Assert === false:

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

.arguments

A

var args = (function(){ return arguments; })(1,2,3);
args.should.be.arguments;
[].should.not.be.arguments;

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

.empty

A

[].should.be.empty
‘‘.should.be.empty
({ length: 0 }).should.be.empty

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

.eql

A

Asserts equality

({ foo: ‘bar’ }).should.eql({ foo: ‘bar’ })

[1,2,3].should.eql([1,2,3])

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

equal

A

Strict Equality

should. strictEqual(undefined, value)
should. strictEqual(false, value)
(4) .should.equal(4)

‘test’.should.equal(‘test’)

[1,2,3].should.not.equal([1,2,3])

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

.within

A

Assert inclusive numeric range:

user.age.should.be.within(5, 50)

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

.a(‘typeof’)

A

Asserts typeof

user.should.be.a(‘object’)
‘test’.should.be.a(‘string’)

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

instanceof

A

user.should.be.an.instanceof(User)

[].should.be.an.instanceOf(Array)

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

.above( int )

A

Assert numeric value above the given value:

user. age.should.be.above(5)
user. age.should.not.be.above(100)

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

.below( int )

A

Assert numeric value below the given value:

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

.match

A

Assert regexp match:

username.should.match(/^\w+$/)

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

.length( int )

A

Assert length property exists and has a value of the given number:

user. pets.should.have.length(5)
user. pets.should.have.a.lengthOf(5)

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

.property

A

Assert property exists and has optional value:

user. should.have.property(‘name’)
user. should.have.property(‘age’, 15)
user. should.not.have.property(‘rawr’)
user. should.not.have.property(‘age’, 0)

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

.ownProperty

A

Asserts own property.

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

.status(code)

A

Assets status code is ###.

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

.header(field[, value])

A

Asserts that a .headers object with field and optional value are present:

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

.json

A

Assert that Content-Type is “application/json; charset=utf-8”

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

.html

A

Assert that Content-Type is “text/html; charset=utf-8”

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

include(obj)

A

Assert that the given obj is present via indexOf(), so this works for strings, arrays, or custom objects implementing indexOf.

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

includeEql(obj)

A

Assert that an object equal to the given obj is present in an Array:

23
Q

throw()

A

Assert an exception is thrown

24
Q

throwError()

A

An alias of throw, its purpose is to be an option for those who run jshint in strict mode.

25
keys
Assert own object keys, which must match exactly, and will fail if you omit a key or two:
26
.and
Provide a AND relationship between asserts.
27
.have
Provides an assert requirement.
28
.have
Provides an assert requirement.
29
.true
Assert === true:
30
.false
Assert === false:
31
.arguments
var args = (function(){ return arguments; })(1,2,3); args.should.be.arguments; [].should.not.be.arguments;
32
.empty
[].should.be.empty ''.should.be.empty ({ length: 0 }).should.be.empty
33
.eql
Asserts equality ({ foo: 'bar' }).should.eql({ foo: 'bar' }) [1,2,3].should.eql([1,2,3])
34
equal
Strict Equality should. strictEqual(undefined, value) should. strictEqual(false, value) (4) .should.equal(4) 'test'.should.equal('test') [1,2,3].should.not.equal([1,2,3])
35
.within
Assert inclusive numeric range: user.age.should.be.within(5, 50)
36
.a('typeof')
Asserts typeof user.should.be.a('object') 'test'.should.be.a('string')
37
instanceof
user.should.be.an.instanceof(User) | [].should.be.an.instanceOf(Array)
38
.above( int )
Assert numeric value above the given value: user. age.should.be.above(5) user. age.should.not.be.above(100)
39
.below( int )
Assert numeric value below the given value:
40
.match
Assert regexp match: username.should.match(/^\w+$/)
41
.length( int )
Assert length property exists and has a value of the given number: user. pets.should.have.length(5) user. pets.should.have.a.lengthOf(5)
42
.property
Assert property exists and has optional value: user. should.have.property('name') user. should.have.property('age', 15) user. should.not.have.property('rawr') user. should.not.have.property('age', 0)
43
.ownProperty
Asserts own property.
44
.status(code)
Assets status code is ###.
45
.header(field[, value])
Asserts that a .headers object with field and optional value are present:
46
.json
Assert that Content-Type is "application/json; charset=utf-8"
47
.html
Assert that Content-Type is "text/html; charset=utf-8"
48
include(obj)
Assert that the given obj is present via indexOf(), so this works for strings, arrays, or custom objects implementing indexOf.
49
includeEql(obj)
Assert that an object equal to the given obj is present in an Array:
50
throw()
Assert an exception is thrown
51
throwError()
An alias of throw, its purpose is to be an option for those who run jshint in strict mode.
52
keys
Assert own object keys, which must match exactly, and will fail if you omit a key or two:
53
.and
Provide a AND relationship between asserts.
54
.have
Provides an assert requirement.