Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

react native testing library, async tests passing but receiving state updates need to be wrapped in act

$
0
0

hey all I have working tests and I know it wants me to wrap my render in an act but if I do that I get a warning stating it can't find root. yet if I then instead change it to create i can't use my getbyTestId method.

`it('should not render image', async () => {        // Arrange        // needs to be used to support async mounting methods like useeffect/componentdidmount        jest.useFakeTimers();        const testComment = {            text: 'placeholder'        } as WorkItemComment;        await act(async () => {            AsyncStorage.setItem('authMethod', 'msa')        });        const placeholderComment: WorkItemComment = testComment;        const placeholderImage: string = 'image';        // Act        const { queryByTestId } = render(<CommentList workItemComments={[placeholderComment]} profilePicture={[placeholderImage]} />);        // Assert        await wait(() => {            expect(queryByTestId('image')).toBeNull();        })    });`

actual component its rendering and where believe this error is stemming from.

`const fetch = async () => {    const authMethod = await AsyncStorage.getItem('authMethod');    setAuthMethod(authMethod!)  };  useEffect(() => {    fetch();  }, [props.workItemComments]);`

my actual error message is as followsconsole.error node_modules/react-native/Libraries/LogBox/LogBox.js:33Warning: An update to CommentList inside a test was not wrapped in act(...).

When testing, code that causes React state updates should be wrapped into act(...):act(() => {  /* fire events that update state */});/* assert on the output */This ensures that you're testing the behavior the user would see in the browser    in CommentList    in View (created by View)    in View (created by AppContainer)    in View (created by View)    in View (created by AppContainer)    in AppContainer (at src/index.js:26)

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>