File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
1-js/2-first-steps/20-object-methods/8-chain-calls/_js.view Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments