This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -45,3 +45,37 @@ describe('/products', function() {
45
45
});
46
46
});
47
47
```
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
+ ```
You can’t perform that action at this time.
0 commit comments