-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.js
77 lines (54 loc) · 1.76 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var sinon = require('sinon');
var should = require('should');
require('./should-sinon');
it('should test if given object is sinon stub', function() {
var callback = sinon.spy();
should(null).be.not.a.sinonStub();
should(void 0).be.not.a.sinonStub();
callback.should.be.a.sinonStub();
});
it('should get number of calls', function() {
var callback = sinon.spy();
callback.should.have.callCount(0);
callback.should.not.be.called();
callback.should.not.be.calledOnce();
callback.should.not.be.calledTwice();
callback.should.not.be.calledThrice();
callback();
callback.should.have.callCount(1);
callback.should.be.called();
callback.should.be.calledOnce();
callback.should.not.be.calledTwice();
callback.should.not.be.calledThrice();
callback();
callback.should.have.callCount(2);
callback.should.be.called();
callback.should.not.be.calledOnce();
callback.should.be.calledTwice();
callback.should.not.be.calledThrice();
callback();
callback.should.have.callCount(3);
callback.should.be.called();
callback.should.not.be.calledOnce();
callback.should.not.be.calledTwice();
callback.should.be.calledThrice();
callback();
callback.should.have.callCount(4);
callback.should.be.called();
callback.should.not.be.calledOnce();
callback.should.not.be.calledTwice();
callback.should.not.be.calledThrice();
});
it('should check if stub was called with specific this', function () {
var callback = sinon.spy();
var obj = {};
callback.call(obj);
callback.should.be.calledOn(obj);
var obj2 = {};
callback.call(obj);
callback.should.be.alwaysCalledOn(obj);
callback.call(obj2);
callback.should.not.be.alwaysCalledOn(obj);
callback.should.not.be.alwaysCalledOn(obj2);
callback.should.be.calledOn(obj2);
});