I am working on a new project that consist on a backend API and a react/redux frontend app. I am setting up my first test using jest/enzyme/moxios.
My issue is that, when the api server is not running the test returns "Network error", but all test are ok if the server is up.
This is my jest test (CRA):
import React from "react";
import { mount } from "enzyme";
import moxios from "moxios";
import Root from "../Root";
import App from "../App";
beforeEach(() => {
moxios.install();
moxios.stubRequest("*/products", {
status: 200,
response: [
{
id: 0,
name: "Test product 0",
description: "Test description 0",
price: 55.6
},
{
id: 2,
name: "Test product 2",
description: "Test description 2",
price: 55.6
}
]
});
});
afterEach(() => {
moxios.uninstall();
});
it("can fetch a list of products and display them", done => {
const wrapped = mount(
<Root>
<App />
</Root>
);
moxios.wait(() => {
wrapped.update();
console.log(wrapped.find("li").html());
expect(wrapped.find("li").length).toEqual(2);
done();
wrapped.unmount();
});
});
It seems like moxios is not working as expected but i couldnt find the reason... i also checked that the axios adapter is moxios:
console.log src/__tests__/productsIntegration.test.js:38
[Function: mockAdapter]