@@ -9,9 +9,31 @@ The following helpers are designed to generate [mocha] tests against
9
9
10
10
## install
11
11
12
- ``` sh
13
- npm install loopback-testing --save-dev
14
- ```
12
+ 1 . ` npm install loopback-testing --save-dev `
13
+ 2 . Assuming you started with a clean template/project generated by ` slc loopback `
14
+ 1 . If you have mocha installed as a global npm module that's great! Simply update ` <your_project>/package.json ` with:
15
+
16
+ ```
17
+ {
18
+ ...
19
+ "scripts": {
20
+ ...
21
+ "test": "mocha"
22
+ }
23
+ }
24
+ ```
25
+ 2. Otherwise, you can utilize the mocha library within the `loopback-testing` testing module:
26
+
27
+ ```
28
+ {
29
+ ...
30
+ "scripts": {
31
+ ...
32
+ "test": "./node_modules/loopback-testing/node_modules/.bin/mocha"
33
+ }
34
+ }
35
+ ```
36
+ 3. Run `npm test` to execute any tests under the `test` directory.
15
37
16
38
## basic usage
17
39
@@ -29,6 +51,7 @@ Use the `loopback-testing` module to generate `mocha` tests.
29
51
``` js
30
52
var lt = require (' loopback-testing' );
31
53
var assert = require (' assert' );
54
+ var app = require (' ../server/server.js' ); // path to app.js or server.js
32
55
33
56
describe (' /products' , function () {
34
57
lt .beforeEach .withApp (app);
@@ -38,7 +61,7 @@ describe('/products', function() {
38
61
assert .equal (this .res .statusCode , 200 );
39
62
});
40
63
41
- lt .givenModel (' product' );
64
+ lt .beforeEach . givenModel (' product' );
42
65
it (' should respond with an array of products' , function () {
43
66
assert (Array .isArray (this .res .body ));
44
67
});
0 commit comments