From 098a1954615a5ed3ebec5555152d27c322ded841 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 9 Apr 2021 00:16:43 -0500 Subject: [PATCH] test: fix the failing tests --- spec/async-helper.js | 32 ------------------------------ spec/tree-view-package-spec.coffee | 13 +++++------- 2 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 spec/async-helper.js diff --git a/spec/async-helper.js b/spec/async-helper.js deleted file mode 100644 index 7d0b23a9..00000000 --- a/spec/async-helper.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Spy on an async method and call through - * @param obj {Record} - * @param method {string} - * @returns {Jasmine.Spy & {resolvedWith: any, calledWith: Array}} - */ -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.call(obj, ...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 diff --git a/spec/tree-view-package-spec.coffee b/spec/tree-view-package-spec.coffee index e19a0971..cce1cdb0 100644 --- a/spec/tree-view-package-spec.coffee +++ b/spec/tree-view-package-spec.coffee @@ -3169,7 +3169,7 @@ describe "TreeView", -> finishRemovalSpy = spyOn(treeView, 'finishRemoval').andCallThrough() - removeSelectedPathsPermanentlySpy = spyOnAsyncAndCallThrough(treeView, 'removeSelectedPathsPermanently') + removeSelectedPathsPermanentlySpy = spyOn(treeView, 'removeSelectedPathsPermanently').andCallThrough() removeSelectedEntriesSpy = spyOn(treeView, 'removeSelectedEntries').andCallThrough() filePath = path.join(os.tmpdir(), 'non-project-file.txt') @@ -3181,26 +3181,23 @@ describe "TreeView", -> waitsForPromise -> atom.commands.dispatch(treeView.element, 'tree-view:remove-permanently') - waitsFor -> - removeSelectedPathsPermanentlySpy.calledWith isnt undefined - waitsFor 'removeSelectedEntries amd removeSelectedPathsPermanently to be called', -> removeSelectedEntriesSpy.callCount is 1 and removeSelectedEntriesSpy.mostRecentCall.args[0] is true and - removeSelectedPathsPermanentlySpy.calledWith[0] is [filePath] + removeSelectedPathsPermanentlySpy.mostRecentCall.args[0][0] is filePath # The internal functionality of the followings are already tested in treeview:remove waitsFor 'it calls onWillDeleteEntry', -> onWillDeleteEntrySpy.callCount is 1 and - onWillDeleteEntrySpy.mostRecentCall.args[0] is {pathToDelete: filePath} + onWillDeleteEntrySpy.mostRecentCall.args[0].pathToDelete is filePath waitsFor 'it calls onEntryDeleted', -> onEntryDeletedSpy.callCount is 1 and - onEntryDeletedSpy.mostRecentCall.args[0] is {pathToDelete: filePath} + onEntryDeletedSpy.mostRecentCall.args[0].pathToDelete is filePath waitsFor 'it calls finishRemoval', -> finishRemovalSpy.callCount is 1 and - finishRemovalSpy.mostRecentCall.args[0] is removeSelectedPathsPermanentlySpy.calledWith[1][0] + finishRemovalSpy.mostRecentCall.args[0] is removeSelectedPathsPermanentlySpy.mostRecentCall.args[1][0] describe "file system events", -> temporaryFilePath = null