Skip to content

Commit 42f7dc1

Browse files
committed
Fix type checking in unit tests
1 parent eb1a597 commit 42f7dc1

28 files changed

Lines changed: 281 additions & 252 deletions

test/nodes/core/analysis/72-sentiment_spec.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ describe('sentiment Node', function() {
6060
var jn1 = helper.getNode("jn1");
6161
var jn2 = helper.getNode("jn2");
6262
jn2.on("input", function(msg) {
63-
msg.should.have.property('sentiment');
64-
msg.sentiment.should.have.property('score');
65-
msg.sentiment.score.should.be.a.number;
66-
msg.sentiment.score.should.be.above(10);
67-
done();
63+
try {
64+
msg.should.have.property('sentiment');
65+
msg.sentiment.should.have.property('score');
66+
msg.sentiment.score.should.be.a.Number();
67+
msg.sentiment.score.should.be.above(10);
68+
done();
69+
} catch(err) {
70+
done(err);
71+
}
6872
});
6973
var testString = 'good, great, best, brilliant';
7074
jn1.receive({payload:testString});
@@ -80,7 +84,7 @@ describe('sentiment Node', function() {
8084
jn2.on("input", function(msg) {
8185
msg.should.have.property('sentiment');
8286
msg.sentiment.should.have.property('score');
83-
msg.sentiment.score.should.be.a.number;
87+
msg.sentiment.score.should.be.a.Number();
8488
msg.sentiment.score.should.be.below(-10);
8589
done();
8690
});
@@ -98,7 +102,7 @@ describe('sentiment Node', function() {
98102
jn2.on("input", function(msg) {
99103
msg.should.have.property('sentiment');
100104
msg.sentiment.should.have.property('score');
101-
msg.sentiment.score.should.be.a.number;
105+
msg.sentiment.score.should.be.a.Number();
102106
msg.sentiment.score.should.equal(20);
103107
done();
104108
});

test/nodes/core/core/25-catch_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('catch Node', function() {
3232
var n2 = helper.getNode("n2");
3333
n1.should.have.property('name', 'catch');
3434
n2.on("input", function(msg) {
35-
msg.should.be.a.Error;
35+
msg.should.be.a.Error();
3636
msg.toString().should.equal("Error: big error");
3737
done();
3838
});

test/nodes/core/core/58-debug_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('debug node', function() {
6969
count++;
7070
}, function() {
7171
try {
72-
helper.log().called.should.be.true;
72+
helper.log().called.should.be.true();
7373
var logEvents = helper.log().args.filter(function(evt) {
7474
return evt[0].type == "debug";
7575
});

test/nodes/core/core/75-exec_spec.js

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('exec node', function() {
6666
n2.on("input", function(msg) {
6767
//console.log(msg);
6868
msg.should.have.property("payload");
69-
msg.payload.should.be.a.String;
69+
msg.payload.should.be.a.String();
7070
msg.payload.should.equal("echo");
7171
});
7272
n3.on("input", function(msg) {
@@ -99,13 +99,13 @@ describe('exec node', function() {
9999
n2.on("input", function(msg) {
100100
//console.log(msg);
101101
msg.should.have.property("payload");
102-
msg.payload.should.be.a.String;
102+
msg.payload.should.be.a.String();
103103
msg.payload.should.equal("echo and more");
104104
});
105105
n3.on("input", function(msg) {
106106
//console.log(msg);
107107
msg.should.have.property("payload");
108-
msg.payload.should.be.a.String;
108+
msg.payload.should.be.a.String();
109109
msg.payload.should.equal("ECHO AND MORE");
110110
done();
111111
child_process.exec.restore();
@@ -130,11 +130,15 @@ describe('exec node', function() {
130130
var n4 = helper.getNode("n4");
131131
n2.on("input", function(msg) {
132132
//console.log("n2",msg);
133-
msg.should.have.property("payload");
134-
msg.payload.should.be.a.Buffer;
135-
msg.payload.length.should.equal(4);
136-
done();
137-
child_process.exec.restore();
133+
try {
134+
msg.should.have.property("payload");
135+
Buffer.isBuffer(msg.payload).should.be.true();
136+
msg.payload.length.should.equal(4);
137+
child_process.exec.restore();
138+
done();
139+
} catch(err) {
140+
done(err);
141+
}
138142
});
139143
n1.receive({});
140144
});
@@ -183,10 +187,14 @@ describe('exec node', function() {
183187
var n4 = helper.getNode("n4");
184188
n2.on("input", function(msg) {
185189
//console.log(msg);
186-
msg.should.have.property("payload");
187-
msg.payload.should.be.a.String;
188-
msg.payload.should.equal("hello world\n");
189-
done();
190+
try {
191+
msg.should.have.property("payload");
192+
msg.payload.should.be.a.String();
193+
msg.payload.should.equal("hello world\n");
194+
done();
195+
} catch(err) {
196+
done(err);
197+
}
190198
});
191199
n1.receive({payload:"hello world"});
192200
});
@@ -204,7 +212,7 @@ describe('exec node', function() {
204212
n2.on("input", function(msg) {
205213
//console.log(msg);
206214
msg.should.have.property("payload");
207-
msg.payload.should.be.a.String;
215+
msg.payload.should.be.a.String();
208216
msg.payload.should.equal("12345 deg C\n");
209217
done();
210218
});
@@ -222,16 +230,20 @@ describe('exec node', function() {
222230
var n3 = helper.getNode("n3");
223231
var n4 = helper.getNode("n4");
224232
n2.on("input", function(msg) {
225-
msg.should.have.property("payload");
226-
msg.payload.should.be.a.Buffer;
227-
msg.payload.length.should.equal(7);
228-
done();
233+
try {
234+
msg.should.have.property("payload");
235+
Buffer.isBuffer(msg.payload).should.be.true();
236+
msg.payload.length.should.equal(7);
237+
done();
238+
} catch(err) {
239+
done(err);
240+
}
229241
});
230242
n1.receive({payload:new Buffer([0x01,0x02,0x03,0x88])});
231243
});
232244
});
233245

234-
it('should now work if passed multiple words to spawn command', function(done) {
246+
it('should work if passed multiple words to spawn command', function(done) {
235247
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo this now works", addpay:false, append:"", useSpawn:true},
236248
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
237249
helper.load(execNode, flow, function() {
@@ -241,14 +253,18 @@ describe('exec node', function() {
241253
var n4 = helper.getNode("n4");
242254
n2.on("input", function(msg) {
243255
msg.should.have.property("payload");
244-
msg.payload.should.be.a.String;
256+
msg.payload.should.be.a.String();
245257
msg.payload.should.equal("this now works\n");
246258
});
247259
n4.on("input", function(msg) {
248-
msg.should.have.property("payload");
249-
msg.payload.should.be.a.String;
250-
msg.payload.should.equal(0);
251-
done();
260+
try {
261+
msg.should.have.property("payload");
262+
msg.payload.should.be.a.Number();
263+
msg.payload.should.equal(0);
264+
done();
265+
} catch(err) {
266+
done(err);
267+
}
252268
});
253269
n1.receive({payload:null});
254270
});
@@ -264,7 +280,7 @@ describe('exec node', function() {
264280
var n4 = helper.getNode("n4");
265281
n4.on("input", function(msg) {
266282
msg.should.have.property("payload");
267-
msg.payload.should.be.a.Number;
283+
msg.payload.should.be.a.Number();
268284
msg.payload.should.be.below(0);
269285
done();
270286
});
@@ -282,12 +298,12 @@ describe('exec node', function() {
282298
var n4 = helper.getNode("n4");
283299
n3.on("input", function(msg) {
284300
msg.should.have.property("payload");
285-
msg.payload.should.be.a.String;
301+
msg.payload.should.be.a.String();
286302
msg.payload.should.equal("mkdir: /foo/bar/doo: No such file or directory\n");
287303
});
288304
n4.on("input", function(msg) {
289305
msg.should.have.property("payload");
290-
msg.payload.should.be.a.String;
306+
msg.payload.should.be.a.Number();
291307
msg.payload.should.equal(1);
292308
done();
293309
});

test/nodes/core/core/80-function_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('function node', function() {
165165
var n1 = helper.getNode("n1");
166166
n1.receive({payload:"foo",topic: "bar"});
167167
try {
168-
helper.log().called.should.be.true;
168+
helper.log().called.should.be.true();
169169
var logEvents = helper.log().args.filter(function(evt) {
170170
return evt[0].type == "function";
171171
});
@@ -188,7 +188,7 @@ describe('function node', function() {
188188
var n1 = helper.getNode("n1");
189189
n1.receive({payload: "foo", topic: "bar"});
190190
try {
191-
helper.log().called.should.be.true;
191+
helper.log().called.should.be.true();
192192
var logEvents = helper.log().args.filter(function (evt) {
193193
return evt[0].type == "function";
194194
});
@@ -210,7 +210,7 @@ describe('function node', function() {
210210
var n1 = helper.getNode("n1");
211211
n1.receive({payload: "foo", topic: "bar"});
212212
try {
213-
helper.log().called.should.be.true;
213+
helper.log().called.should.be.true();
214214
var logEvents = helper.log().args.filter(function (evt) {
215215
return evt[0].type == "function";
216216
});
@@ -232,7 +232,7 @@ describe('function node', function() {
232232
var n1 = helper.getNode("n1");
233233
n1.receive({payload: "foo", topic: "bar"});
234234
try {
235-
helper.log().called.should.be.true;
235+
helper.log().called.should.be.true();
236236
var logEvents = helper.log().args.filter(function (evt) {
237237
return evt[0].type == "function";
238238
});

test/nodes/core/core/89-delay_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('delay Node', function() {
294294
}
295295
}
296296
}
297-
foundAtLeastOneDrop.should.be.true;
297+
foundAtLeastOneDrop.should.be.true();
298298
done();
299299
} catch (err) {
300300
done(err);

test/nodes/core/logic/15-change_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('change Node', function() {
217217
var helperNode1 = helper.getNode("helperNode1");
218218
helperNode1.on("input", function(msg) {
219219
try {
220-
(msg.payload === null).should.be.true;
220+
(msg.payload === null).should.be.true();
221221
done();
222222
} catch(err) {
223223
done(err);

test/nodes/core/logic/17-split_spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('JOIN node', function() {
154154
n2.on("input", function(msg) {
155155
try {
156156
msg.should.have.property("payload");
157-
msg.payload.should.be.an.Array;
157+
msg.payload.should.be.an.Array();
158158
msg.payload[0].should.equal(1);
159159
msg.payload[1].should.equal(true);
160160
//msg.payload[2].a.should.equal(1);
@@ -274,7 +274,7 @@ describe('JOIN node', function() {
274274
n2.on("input", function(msg) {
275275
try {
276276
msg.should.have.property("payload");
277-
msg.payload.should.be.an.Array;
277+
msg.payload.should.be.an.Array();
278278
msg.payload[0].should.equal(1);
279279
msg.payload[1].should.equal(2);
280280
msg.payload[2].should.equal(3);
@@ -323,8 +323,8 @@ describe('JOIN node', function() {
323323
n2.on("input", function(msg) {
324324
try {
325325
msg.should.have.property("payload");
326-
msg.payload.should.be.an.Array;
327-
(msg.payload[0] === undefined).should.be.true;
326+
msg.payload.should.be.an.Array();
327+
(msg.payload[0] === undefined).should.be.true();
328328
msg.payload[1].should.equal(2);
329329
msg.payload[2].should.equal(3);
330330
msg.payload[3].should.equal(4);
@@ -347,7 +347,7 @@ describe('JOIN node', function() {
347347
n2.on("input", function(msg) {
348348
try {
349349
msg.should.have.property("payload");
350-
msg.payload.should.be.an.Array;
350+
msg.payload.should.be.an.String();
351351
msg.payload.should.equal("abcd");
352352
done();
353353
}

test/nodes/core/parsers/70-HTML_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('html node', function() {
3232
});
3333

3434
beforeEach(function() {
35-
fs.existsSync(file).should.be.true;
35+
fs.existsSync(file).should.be.true();
3636
});
3737

3838
afterEach(function() {
@@ -170,7 +170,7 @@ describe('html node', function() {
170170
var n1 = helper.getNode("n1");
171171
var n2 = helper.getNode("n2");
172172
n1.receive({payload:null,topic: "bar"});
173-
helper.log().called.should.be.true;
173+
helper.log().called.should.be.true();
174174
var logEvents = helper.log().args.filter(function(evt) {
175175
return evt[0].type == "html";
176176
});

test/nodes/core/storage/28-tail_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('tail Node', function() {
156156
msg.should.have.property('topic', fileToTail);
157157
inputCounter++;
158158
if (inputCounter === 1) {
159-
warned.should.be.false;
159+
warned.should.be.false();
160160
msg.payload.should.equal("Tail message line append");
161161
} else if (inputCounter === 2) {
162162
msg.payload.should.equal("Tail message line truncate");
@@ -166,7 +166,7 @@ describe('tail Node', function() {
166166
167167
if (inputCounter === 5) {
168168
setTimeout(function() {
169-
warned.should.be.true;
169+
warned.should.be.true();
170170
done();
171171
},100);
172172
}

0 commit comments

Comments
 (0)