Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit ad72c8a

Browse files
pulkitsinghalPulkit Singhal
authored andcommitted
README: add basic mocha setup instructions
Update README with instructions on how to configure `npm test` to run unit tests using mocha.
1 parent 3625c0c commit ad72c8a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,31 @@ The following helpers are designed to generate [mocha] tests against
99

1010
## install
1111

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.
1537
1638
## basic usage
1739
@@ -29,6 +51,7 @@ Use the `loopback-testing` module to generate `mocha` tests.
2951
```js
3052
var lt = require('loopback-testing');
3153
var assert = require('assert');
54+
var app = require('../server/server.js'); //path to app.js or server.js
3255

3356
describe('/products', function() {
3457
lt.beforeEach.withApp(app);
@@ -38,7 +61,7 @@ describe('/products', function() {
3861
assert.equal(this.res.statusCode, 200);
3962
});
4063

41-
lt.givenModel('product');
64+
lt.beforeEach.givenModel('product');
4265
it('should respond with an array of products', function() {
4366
assert(Array.isArray(this.res.body));
4467
});

0 commit comments

Comments
 (0)