Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,37 @@ describe('/products', function() {
});
});
```

## 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.

```js
var TestDataBuilder = require('loopback-testing').TestDataBuilder;
var ref = TestDataBuilder.ref;

// The context object to hold the created models.
// You can use `this` in mocha test instead.
var context = {};

var ref = TestDataBuilder.ref;
new TestDataBuilder()
.define('application', Application, {
pushSettings: { stub: { } }
})
.define('device', Device, {
// use the value of application's id
// the value is resolved at build time
appId: ref('application.id'),
deviceType: 'android'
})
.define('notification', Notification)
.buildTo(context, function(err) {
// test models are available as
// context.application
// context.device
// context.notification
});
```