@@ -82,6 +82,63 @@ describe('debug', function () {
82
82
83
83
expect ( log . log ) . to . have . been . calledThrice ;
84
84
} ) ;
85
+
86
+ it ( 'times a critical function' , function ( ) {
87
+ log . log = sinon . spy ( ) ;
88
+
89
+ var result = log . time ( 'a critical function' , function ( ) {
90
+ log ( 'hello from inside' ) ;
91
+ return 1234 ;
92
+ } ) ;
93
+
94
+ expect ( result ) . to . equal ( 1234 ) ;
95
+ expect ( log . log ) . to . have . been . calledThrice ;
96
+ } ) ;
97
+
98
+ if ( typeof Promise !== 'undefined' ) {
99
+ it ( 'times a critical asynchronous function' , function ( cb ) {
100
+ log . log = sinon . spy ( ) ;
101
+
102
+ log . time ( 'a critical function' , function ( ) {
103
+ return new Promise ( function ( resolve ) {
104
+ log ( 'hello from the inside' ) ;
105
+ resolve ( 1234 ) ;
106
+ } ) ;
107
+ } ) . then ( function ( result ) {
108
+ expect ( result ) . to . equal ( 1234 ) ;
109
+ expect ( log . log ) . to . have . been . calledThrice ;
110
+ cb ( ) ;
111
+ } ) . catch ( cb ) ;
112
+ } ) ;
113
+ }
114
+
115
+ it ( 'should throw if there aren\'t enough arguments' , function ( ) {
116
+ log . log = sinon . stub ( ) ;
117
+
118
+ expect ( function ( ) {
119
+ log . time ( ) ;
120
+ } ) . to . throw ( 'debug.time() takes at least a debug string and a function' ) ;
121
+
122
+ expect ( function ( ) {
123
+ log . time ( 'hello' ) ;
124
+ } ) . to . throw ( 'debug.time() takes at least a debug string and a function' ) ;
125
+
126
+ expect ( function ( ) {
127
+ log . time ( function ( ) { } ) ;
128
+ } ) . to . throw ( 'debug.time() takes at least a debug string and a function' ) ;
129
+ } ) ;
130
+
131
+ it ( 'should throw if last argument isn\'t a function' , function ( ) {
132
+ log . log = sinon . stub ( ) ;
133
+
134
+ expect ( function ( ) {
135
+ log . time ( 'hello' , 1234 ) ;
136
+ } ) . to . throw ( 'the last argument to debug.time() must be a function' ) ;
137
+
138
+ expect ( function ( ) {
139
+ log . time ( 'hello' , function ( ) { } , 1235 ) ;
140
+ } ) . to . throw ( 'the last argument to debug.time() must be a function' ) ;
141
+ } ) ;
85
142
} ) ;
86
143
} ) ;
87
144
} ) ;
0 commit comments