[Vuejs]-Test is passing, but assertion error given after

0👍

After spending another day I am able to suplie solution to my problem.

I have modified jest-setup.js to be able to use async await.

-  test("addContact", () => {
+  test("addContact", async () => {

... //  no changes

-    flushPromises()
-     .then(() => {

+    await flushPromises();

     expect(1).toBe(2); // <-- now test fail here as expected ;-)

     expect(wrapper.vm.saving).toBe(false);
     expect(window.toastr.error).toHaveBeenCalled();
     expect(wrapper.emitted("update")[0][0]).toEqual([...contacts, newContact]);
   })
-     .catch((error) => {
-       throw Error(error)
-     })

   });

Anthough this works correctly now, I still don’t know why Promise didin’t work. So any suggestions are still welcome 🙂

Leave a comment