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.

This commit is contained in:
Jason Wheeler 2022-11-03 12:58:19 -04:00
parent 6fe6628dec
commit 67f2707995
4 changed files with 67 additions and 25 deletions

View file

@ -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 () => {

View file

@ -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

View file

@ -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
}
});
});

View file

@ -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
}
});
});
});