Skip to content

Commit d5edb6c

Browse files
committed
ok
1 parent 0ff5058 commit d5edb6c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
let ladder = {
3+
step: 0,
4+
up: function() {
5+
this.step++;
6+
return this;
7+
},
8+
down: function() {
9+
this.step--;
10+
return this;
11+
},
12+
showStep: function() {
13+
alert(this.step);
14+
}
15+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
describe('Ladder', function() {
3+
before(function() {
4+
window.alert = sinon.stub(window, "alert");
5+
});
6+
7+
beforeEach(function() {
8+
ladder.step = 0;
9+
});
10+
11+
it('up() should return this', function() {
12+
assert.equal(ladder.up(), ladder);
13+
});
14+
15+
it('down() should return this', function() {
16+
assert.equal(ladder.down(), ladder);
17+
});
18+
19+
it('showStep() should call alert', function() {
20+
ladder.showStep();
21+
assert(alert.called);
22+
});
23+
24+
it('up() should increase step', function() {
25+
assert.equal(ladder.up().up().step, 2);
26+
});
27+
28+
it('down() should decrease step', function() {
29+
assert.equal(ladder.down().step, -1);
30+
});
31+
32+
it('down().up().up().up() ', function() {
33+
assert.equal(ladder.down().up().up().up().step, 2);
34+
});
35+
36+
after(function() {
37+
ladder.step = 0;
38+
alert.restore();
39+
});
40+
});

0 commit comments

Comments
 (0)