I do not want to read the code for hours to find the corresponding part, but I am curious how jasmine fulfills its clock. Interestingly, it can test asynchronous code with a synchronization check code. AFAIK, with the current node.js that supports ES5, this is not possible (asynchronous functions are defined in ES7). Does it parse js code with something like estraverse and create an asynchronous test from synchronization?
Just an example of what I'm talking about:
it("can test async code with sync testing code", function () { jasmine.clock().install(); var i = 0; var asyncIncrease = function () { setTimeout(function () { ++i; }, 1); }; expect(i).toBe(0); asyncIncrease(); expect(i).toBe(0); jasmine.clock().tick(2); expect(i).toBe(1); jasmine.clock().uninstall(); });
Here expect(i).toBe(1); must be in a callback.
inf3rno
source share