@@ -11,67 +11,67 @@ Here are examples using *mocha* with *chai*'s *expect*. See the [Chai/Expect doc
11
11
#### exists
12
12
13
13
``` js
14
- it (' doesn\' t exist' , function () {
14
+ it (' doesn\' t exist' , () => {
15
15
expect (target).to .be .defined ;
16
16
});
17
17
```
18
18
19
19
#### type
20
20
21
21
``` js
22
- it (' should be a function' , function () {
22
+ it (' should be a function' , () => {
23
23
expect (target).to .be .a (' function' );
24
24
});
25
25
```
26
26
27
27
#### function params
28
28
29
29
``` js
30
- it (' should have two parameters' , function () {
30
+ it (' should have two parameters' , () => {
31
31
expect (target).to .have .length (2 );
32
32
});
33
33
```
34
34
35
35
#### function returns
36
36
37
37
``` js
38
- it (' should add one to the number' , function () {
38
+ it (' should add one to the number' , () => {
39
39
expect (addOne (1 )).to .equal (2 );
40
40
});
41
41
```
42
42
43
43
#### equals
44
44
45
45
``` js
46
- it (' should be 42' , function () {
46
+ it (' should be 42' , () => {
47
47
expect (target).to .equal (42 );
48
48
});
49
49
```
50
50
51
51
#### deep equals (with objects or arrays)
52
52
53
53
``` js
54
- it (' should be {a: 42}' , function () {
54
+ it (' should be {a: 42}' , () => {
55
55
expect (target).to .deep .equal ({a: 42 });
56
56
});
57
57
```
58
58
59
59
#### regex
60
60
61
61
``` js
62
- it (' should include the variable "count"' , function () {
63
- var regex = new RegExp (' count' );
64
- var string = target .toString ();
62
+ it (' should include the variable "count"' , () => {
63
+ const regex = new RegExp (' count' );
64
+ const string = target .toString ();
65
65
expect (string).to .match (regex);
66
66
});
67
67
```
68
68
69
69
``` js
70
- it (' should access the property "prop"' , function () {
71
- var regex1 = / \. prop/ ; // dot notation
72
- var regex2 = / \[ ["'] prop["'] \] / ; // bracket notation
73
- var string = target .toString ();
74
- var result = !! string .match (regex1) || !! string .match (regex2);
70
+ it (' should access the property "prop"' , () => {
71
+ const regex1 = / \. prop/ ; // dot notation
72
+ const regex2 = / \[ ["'] prop["'] \] / ; // bracket notation
73
+ const string = target .toString ();
74
+ const result = !! string .match (regex1) || !! string .match (regex2);
75
75
expect (result).to .be .true ;
76
76
});
77
77
```
@@ -83,15 +83,18 @@ You can use [*sinon*](http://sinonjs.org/docs/) or [*chai-spies*](https://github
83
83
` > npm i -s chai-spies `
84
84
85
85
``` js
86
- var chai = require (' chai' ),
87
- spies = require (' chai-spies' );
88
- var expect = chai .expect ;
89
- chai .use (spies);
86
+ const chai = require (' chai' );
87
+ const spies = require (' chai-spies' );
88
+ const expect = chai .expect ;
89
+ chai .use (spies);
90
90
91
- var spy = chai . spy . on ( console , ' log ' );
92
- loadJS ( ' 04-forEach.js ' );
91
+ // setup the console.log spy listener
92
+ let spy = chai . spy . on ( console , ' log ' );
93
93
94
- it (' should write "hello world" to the console' , function () {
94
+ // load the user file content
95
+ const example = require (' BASE/path/to/example.js' );
96
+
97
+ it (' should write "hello world" to the console' , () => {
95
98
expect (spy).to .have .been .called .with (' hello world' );
96
99
});
97
100
```
@@ -105,7 +108,7 @@ Some variables are passed into the test runner through the node environment *pro
105
108
See an example of dynamic data based on the task position below:
106
109
107
110
``` js
108
- var data = [1 , 2 , 3 ];
111
+ const data = [1 , 2 , 3 ];
109
112
110
113
if (process .env .TASK_POSITION === ' 4' ) {
111
114
data = [1 , 2 , 3 , 4 ];
0 commit comments