Jest - Warning: You called act(async () => ...) without await

I have a test where I'm trying to test a component's default render compared to a render when something (in this case a 0) is in storage. The component should render the same in both cases. To test this, I need to render the component twice.

import { render, waitFor } from "@testing-library/react-native";
import * as React from "react";
import { View } from "react-native";

it("Shouldn't break when rendering twice...", async () => {
    const firstRender = await waitFor(() => render(<View />));
    const defaultJson = JSON.stringify(firstRender.toJSON()); 
    firstRender.unmount();
  
    putTheThingInAsyncStorage();
    
    const secondRender = await waitFor(() => render(<View />));
    const newJson = JSON.stringify(secondRender.toJSON()); 
    expect(newJson).toBe(defaultJson);
  
    // In this particular test case, they should be the same.
    expect(newJson).toBe(defaultJson);

    removeTheThingFromAsyncStorage();
});

This test works, but the console gives me this nagging warning: Warning: You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);

Because of this, I've added the await waitFor(...); to the render calls, but I still get the warning. At this point, the warning is lying to me because I am, in fact, using the await keyword so I'm not sure what the issue is.

What am I doing wrong?



from Recent Questions - Stack Overflow https://ift.tt/pmUfJcN
https://ift.tt/b0mGdeN

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation