My goal is to override (monkey patch) the it()
function of the Jasmine framework and determine if a function passed as the second argument is of type async
. I attempted using instanceof Promise
since async functions return a promise, but it never evaluates to true. After inspecting logged functions, I noticed that async()
function specs have a return type of tslib_1.awaiter(some args..)
.
Here is my current approach:
let newIt = jasmine.getEnv().it;
jasmine.getEnv().it = function(...args): jasmine.Spec {
// perform actions.
if(args[1] instanceOf Promise) {
debugger; // this block is never executed.
// handle error.
}
return newIt.apply(this, arguments);
}
Can you point out what I might be doing incorrectly here? Any guidance would be greatly appreciated.
Thank you.
Edit: Let's consider two dummy specs, one asynchronous and the other synchronous:
Async Test:
const exp = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1);
}, 500);
});
};
it('asyncTest', async () => {
expect(await exp()).toEqual(1);
}, 600);
Synchronous:
it('testNon', () => {
expect(true).toBe(true);
});