I'm implementing mocha tests in nodejs app application and once again I made a mistake.
Instead of writing it('should ...' , function(done){}); I wrote if('should ...
if ('should implment rest style "destroy" method', function(done){
request(app)
.del('/restLike/41')
.expect(200, '<h1>Rest Like Destroy: 41</h1>')
.end(done);
});
Stupid mistake, if instead of it. But why does it not fail, why nodes v8 compiles it?
It's valid JavaScript!
It is an if statement whose condition is an expression with the comma operator and whose body is the empty statement (;).
The comma operator is defined here. The left-hand operand of the comma operator here is a string, and the right-hand operand is a function expression. The result of the comma-operator expression (which is the function expression) happens to be truthy and the empty body is executed but does nothing.
It may look strange, but it parses -- and executes -- just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With