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

Commit 7df121f

Browse files
author
Miroslav Bajtos
committed
Describe TestDataBuilder in README.
1 parent 5805cef commit 7df121f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,37 @@ describe('/products', function() {
4545
});
4646
});
4747
```
48+
49+
## building test data
50+
51+
Use TestDataBuilder to build many Model instances in one async call. Specify
52+
only properties relevant to your test, the builder will pre-fill remaining
53+
required properties with sensible defaults.
54+
55+
```js
56+
var TestDataBuilder = require('loopback-testing').TestDataBuilder;
57+
var ref = TestDataBuilder.ref;
58+
59+
// The context object to hold the created models.
60+
// You can use `this` in mocha test instead.
61+
var context = {};
62+
63+
var ref = TestDataBuilder.ref;
64+
new TestDataBuilder()
65+
.define('application', Application, {
66+
pushSettings: { stub: { } }
67+
})
68+
.define('device', Device, {
69+
// use the value of application's id
70+
// the value is resolved at build time
71+
appId: ref('application.id'),
72+
deviceType: 'android'
73+
})
74+
.define('notification', Notification)
75+
.buildTo(context, function(err) {
76+
// test models are available as
77+
// context.application
78+
// context.device
79+
// context.notification
80+
});
81+
```

0 commit comments

Comments
 (0)