[Vuejs]-Jest does not continue after async method

0👍

Don’t mix up await and then/catch. Prefer using await unless you have very special cases (see this answer):

test("API success", async () => {
    const ConfirmNameBtn = wrapper.find(".form__submit-name");
    await ConfirmNameBtn.vm.$emit("click");

    const pipelinesApi = new Pipelines();
    jest.spyOn(pipelinesApi, "createPipeline").mockResolvedValue({pipeline_id: 100});

    const {name, description} = wrapper.vm.form;
    const data = await pipelinesApi.createPipeline();

    expect(wrapper.vm.pipelineNameServiceError).toBe(false);

    wrapper.setData({
        idPipelineCreated: data.pipeline_id
    });

    expect(wrapper.vm.idPipelineCreated).toBe(data.pipeline_id)
    expect(wrapper.vm.serviceError).toBe(false);
})

Leave a comment