See my test code using mocha + tamejs:
test/t.tjs
require('should');
function inc(n, callback) {
setTimeout(function() {
console.log('### inc: ' + n);
callback(n+1);
}, 1000);
};
describe('test', function(){
it('show ok with tamejs', function(){
console.log('### testing ...');
var result;
await { inc(1, defer(result)); }
console.log('result: ' + result);
result.should.equal(123456); // won't pass
});
});
Compile it to t.js:
tamejs -o test/t.js test/t.tjs
Run mocha
mocha
Result:
### testing ...
.
✔ 1 test complete (1ms)
It seems the inc method has never been invoked.
The problem is I didn’t use mocha correctly.
It should be wrote as:
Please notice the
done, it used in mocha to determine if a asynchronous invocation has finished or not. Without it, mocha won’t wait for the asynchronous invocation.