This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for remove-permanently
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Spy on an async method and call through | ||
* @param obj {Record<string, Function> | any} | ||
* @param method {string} | ||
* @returns {Jasmine.Spy & {resolvedWith: any, calledWith: Array<any>}} | ||
*/ | ||
function spyOnAsyncAndCallThrough (obj, method) { | ||
const originalMethod = obj[method] | ||
if (typeof originalMethod !== 'function') { | ||
throw new Error(`${method} is not a method of ${obj}`) | ||
} | ||
let resolvedWith | ||
let calledWith | ||
let asyncSpy = spyOn(obj, method) | ||
.andCallFake((...args) => { | ||
calledWith = args | ||
originalMethod(...args) | ||
.then((returnValue) => { | ||
resolvedWith = returnValue | ||
// update spy call information | ||
asyncSpy.resolvedWith = resolvedWith | ||
asyncSpy.calledWith = calledWith | ||
}).catch((err) => { | ||
throw err | ||
}) | ||
}) | ||
// initial undefined values | ||
asyncSpy.resolvedWith = resolvedWith | ||
asyncSpy.calledWith = calledWith | ||
return asyncSpy | ||
} | ||
exports.spyOnAsyncAndCallThrough = spyOnAsyncAndCallThrough |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters