DEPRECATED
This module is no longer maintained by StrongLoop/IBM.
We are encouraging the community to take the ownership of this module. Please open an issue in https://github.com/strongloop/loopback if you are willing to become the new maintainer.
See also https://groups.google.com/forum/#!topic/loopbackjs/w038RvqHeYI
loopback-testing
Utilities for testing LoopBack apps
overview
The following helpers are designed to generate [mocha] tests against LoopBack apps.
install
npm install loopback-testing --save-dev
- Assuming you started with a clean template/project generated by
slc loopback
- If you have mocha installed as a global npm module that's great! Simply update
<your_project>/package.json
with:
```
{
...
"scripts": {
...
"test": "mocha"
}
}
```
- Otherwise, you can utilize the mocha library within the
loopback-testing
testing module:
```
{
...
"scripts": {
...
"test": "./node_modules/loopback-testing/node_modules/.bin/mocha"
}
}
```
- Run
npm test
to execute any tests under thetest
directory.
basic usage
Below is a simple LoopBack app.
var loopback = ;var app = ;var Product = app;Product;
Use the loopback-testing
module to generate mocha
tests.
var lt = ;var assert = ;var app = ; //path to app.js or server.js ;
building test data
Use TestDataBuilder to build many Model instances in one async call. Specify only properties relevant to your test, the builder will pre-fill remaining required properties with sensible defaults.
var TestDataBuilder = TestDataBuilder;var ref = TestDataBuilderref; // The context object to hold the created models.// You can use `this` in mocha test instead.var context = {}; var ref = TestDataBuilderref; ;