Skip to content

Commit f97b325

Browse files
committed
Document API
1 parent 2f07eed commit f97b325

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

README.md

+34-8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ it('should warn if the `somethingGood` prop is falsy', function (done) {
157157
/* ..etc.. */
158158
};
159159
helper.load(FooNode, flow, function () {
160+
var n1 = helper.getNode("n1");
160161
n1.warn.should.be.calledWithExactly('badness');
161162
done();
162163
});
@@ -289,14 +290,14 @@ For additional test examples taken from the Node-RED core, see the `.js` files s
289290

290291
> *Work in progress.*
291292
292-
### load(testNode, testFlows, testCredentials, cb)
293+
### load(testNode, testFlows[, testCredentials][, cb])
293294

294-
Loads a flow then starts the flow. This function has the following arguments:
295+
Return a promise to load a flow then start the flow. This function has the following arguments:
295296

296297
* testNode: (object|array of objects) Module object of a node to be tested returned by require function. This node will be registered, and can be used in testFlows.
297298
* testFlow: (array of objects) Flow data to test a node. If you want to use flow data exported from Node-RED editor, export the flow to the clipboard and paste the content into your test scripts.
298299
* testCredentials: (object) Optional node credentials.
299-
* cb: (function) Function to call back when testFlows has been started.
300+
* cb: (function) Optional function to call back when testFlows has been started.
300301

301302
### unload()
302303

@@ -306,9 +307,34 @@ Return promise to stop all flows, clean up test runtime.
306307

307308
Returns a node instance by id in the testFlow. Any node that is defined in testFlows can be retrieved, including any helper node added to the flow.
308309

310+
An extra method is added to the node:
311+
312+
* next(event)
313+
Alternative to on(event, callback) for async/await style programming. Returns promise to find the next event in queue. If there is no events in queue, the promise itself will be queued.
314+
315+
If the event is input, a clone of the message will be returned.
316+
317+
Example:
318+
319+
````javascript
320+
it('should make payload lower case', async function() {
321+
var flow = [
322+
{id:"n1",type:"lower-case",name:"test name",wires:[["n2"]]},
323+
{id:"n2",type:"helper"}
324+
];
325+
await helper.load(lowerNode, flow);
326+
var n2 = helper.getNode("n2");
327+
var n1 = helper.getNode("n1");
328+
329+
n1.receive({payload:"UpperCase"});
330+
let msg = await n2.next("input");
331+
msg.should.have.property('payload', 'uppercase');
332+
});
333+
````
334+
309335
### clearFlows()
310336

311-
Stop all flows.
337+
Return promise to stop all flows.
312338

313339
### request()
314340

@@ -320,9 +346,9 @@ Example:
320346
helper.request().post('/inject/invalid').expect(404).end(done);
321347
```
322348

323-
### startServer(done)
349+
### startServer([done])
324350

325-
Starts a Node-RED server for testing nodes that depend on http or web sockets endpoints like the debug node.
351+
Return promise to start a Node-RED server for testing nodes that depend on http or web sockets endpoints like the debug node.
326352
To start a Node-RED server before all test cases:
327353

328354
```javascript
@@ -331,9 +357,9 @@ before(function(done) {
331357
});
332358
```
333359

334-
### stopServer(done)
360+
### stopServer([done])
335361

336-
Stop server. Generally called after unload() complete. For example, to unload a flow then stop a server after each test:
362+
Return promise to stop server. Generally called after unload() complete. For example, to unload a flow then stop a server after each test:
337363

338364
```javascript
339365
afterEach(function(done) {

0 commit comments

Comments
 (0)