From 67f2707995c9a3b477ad23d50ca94b228ff760f5 Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Thu, 3 Nov 2022 12:58:19 -0400 Subject: [PATCH] updated pattern for asynchronous testing. It should now fail the test if assertion in promise fails or if an error is thrown during the assertion. --- src/layouts/vehicle-make/vehicle-make.spec.js | 26 +++++++++++----- .../vehicle-model/vehicle-model.spec.js | 30 ++++++++++++++----- .../vehicle-style/vehicle-style.spec.js | 22 ++++++++++---- src/layouts/vehicle-year/vehicle-year.spec.js | 14 ++++++--- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/src/layouts/vehicle-make/vehicle-make.spec.js b/src/layouts/vehicle-make/vehicle-make.spec.js index 0e13d56f..48d995a6 100644 --- a/src/layouts/vehicle-make/vehicle-make.spec.js +++ b/src/layouts/vehicle-make/vehicle-make.spec.js @@ -39,11 +39,17 @@ describe("vehicle-make.vue", () => { ); //Assert - apiPromise.finally(() => { - expect(makeQuestion.methods.initializeComponent).toHaveBeenCalledWith( - makeQuestionInitialData - ); + return apiPromise.finally(() => { + try { + expect(makeQuestion.methods.initializeComponent).toHaveBeenCalledWith( + makeQuestionInitialData + ); + } + catch (e) { + throw e + } }); + }); test("BackButtonAction triggers a router.navigate change", async () => { @@ -68,9 +74,15 @@ describe("vehicle-make.vue", () => { await nextTick(); //Assert - apiPromise.finally(() => { - expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); - }); + return apiPromise.finally(() => { + try { + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + } + catch (e) { + throw e + } + }); + }); test("Year set, arePagePrerequisitesValid should be true ", async () => { diff --git a/src/layouts/vehicle-model/vehicle-model.spec.js b/src/layouts/vehicle-model/vehicle-model.spec.js index 21ddd5fa..7360f795 100644 --- a/src/layouts/vehicle-model/vehicle-model.spec.js +++ b/src/layouts/vehicle-model/vehicle-model.spec.js @@ -36,17 +36,23 @@ describe("vehicle-model.vue", () => { undefined, (c) => c(wrapper.vm) ); + //Assert - apiPromise.finally(() => { - expect(modelQuestion.methods.initializeComponent).toHaveBeenCalledWith( - modelQuestionInitialData - ); + return apiPromise.finally(() => { + try { + expect(modelQuestion.methods.initializeComponent).toHaveBeenCalledWith( + modelQuestionInitialData + ); + } + catch (e) { + throw e + } }); }); }); describe("vehicle-model.vue", () => { - test("BackButtonAction triggers a router.navigateWithoutSaving change", async () => { + test("BackButtonAction triggers a router.navigate change", async () => { //Arrange const { wrapper, apiPromise } = setupMocks({ pageHeaderWidgetHeaderText: "Select a model to get started", @@ -65,12 +71,20 @@ describe("vehicle-model.vue", () => { ); wrapper.vm.backButtonAction(); await nextTick(); + //Assert - apiPromise.finally(() => { - expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); - }); + return apiPromise.finally(() => { + try { + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + } + catch (e) { + throw e + } + }); + }); }); + describe("vehicle-model.vue", () => { test("Make set, arePagePrerequisitesValid should be true ", async () => { //Arrange diff --git a/src/layouts/vehicle-style/vehicle-style.spec.js b/src/layouts/vehicle-style/vehicle-style.spec.js index dca24943..3b055afd 100644 --- a/src/layouts/vehicle-style/vehicle-style.spec.js +++ b/src/layouts/vehicle-style/vehicle-style.spec.js @@ -43,10 +43,15 @@ describe("vehicle-style.vue", () => { ); //Assert - apiPromise.finally(() => { - expect(styleQuestion.methods.initializeComponent).toHaveBeenCalledWith( - styleQuestionInitialData - ); + return apiPromise.finally(() => { + try { + expect(styleQuestion.methods.initializeComponent).toHaveBeenCalledWith( + styleQuestionInitialData + ); + } + catch (e) { + throw e + } }); }); @@ -72,8 +77,13 @@ describe("vehicle-style.vue", () => { await nextTick(); //Assert - apiPromise.finally(() => { - expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + return apiPromise.finally(() => { + try { + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + } + catch (e) { + throw e + } }); }); diff --git a/src/layouts/vehicle-year/vehicle-year.spec.js b/src/layouts/vehicle-year/vehicle-year.spec.js index 0d05479d..5db8c4ed 100644 --- a/src/layouts/vehicle-year/vehicle-year.spec.js +++ b/src/layouts/vehicle-year/vehicle-year.spec.js @@ -36,11 +36,17 @@ describe("vehicle-year.vue", () => { ); //Assert - apiPromise.finally(() => { - expect(yearQuestion.methods.initializeComponent).toHaveBeenCalledWith( - yearQuestionInitialData - ); + return apiPromise.finally(() => { + try { + expect(yearQuestion.methods.initializeComponent).toHaveBeenCalledWith( + yearQuestionInitialData + ); + } + catch (e) { + throw e + } }); + }); });