Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use async version of act() #2880

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ beforeEach(() => {
});

describe('returns LOADING while queries are pending', () => {
test('urlResolver is loading', () => {
test('urlResolver is loading', async () => {
useQuery.mockImplementation(() => {
return { loading: true };
});

act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -96,8 +96,8 @@ describe('returns LOADING while queries are pending', () => {
});
});

test('getRootComponent is pending', () => {
act(() => {
test('getRootComponent is pending', async () => {
await act(() => {
create(<Component />);
});

Expand All @@ -110,12 +110,12 @@ describe('returns LOADING while queries are pending', () => {
});

describe('returns ERROR when queries fail', () => {
test('urlResolver fails', () => {
test('urlResolver fails', async () => {
useQuery.mockImplementation(() => {
return { error: new Error() };
});

act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -130,7 +130,7 @@ describe('returns ERROR when queries fail', () => {
test('getRootComponent fails', async () => {
const routeError = new Error();

act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -151,7 +151,7 @@ describe('returns ERROR when queries fail', () => {
});

describe('returns NOT_FOUND when queries come back empty', () => {
test('urlResolver is null', () => {
test('urlResolver is null', async () => {
useQuery.mockImplementation(() => {
return {
data: {
Expand All @@ -161,7 +161,7 @@ describe('returns NOT_FOUND when queries come back empty', () => {
};
});

act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -174,7 +174,7 @@ describe('returns NOT_FOUND when queries come back empty', () => {
});

describe('returns REDIRECT after receiving a redirect code', () => {
test('redirect code 301', () => {
test('redirect code 301', async () => {
useQuery.mockImplementation(() => {
return {
data: {
Expand All @@ -189,7 +189,7 @@ describe('returns REDIRECT after receiving a redirect code', () => {
};
});

act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -201,7 +201,7 @@ describe('returns REDIRECT after receiving a redirect code', () => {
});
});

test('redirect code 302', () => {
test('redirect code 302', async () => {
useQuery.mockImplementation(() => {
return {
data: {
Expand All @@ -216,7 +216,7 @@ describe('returns REDIRECT after receiving a redirect code', () => {
};
});

act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -231,7 +231,7 @@ describe('returns REDIRECT after receiving a redirect code', () => {

describe('returns FOUND after fetching a component', () => {
test('getRootComponent succeeds', async () => {
act(() => {
await act(() => {
create(<Component />);
});

Expand All @@ -256,15 +256,15 @@ describe('avoids fetching the same component twice', () => {
test('getRootComponent succeeds', async () => {
let tree;

act(() => {
await act(() => {
tree = create(<Component key="a" />);
});

await act(() => {
resolve('MockComponent');
});

act(() => {
await act(() => {
tree.update(<Component key="a" />);
});

Expand All @@ -277,11 +277,11 @@ describe('avoids setting state when unmounted', () => {
test('getRootComponent resolves after unmount', async () => {
let tree;

act(() => {
await act(() => {
tree = create(<Component />);
});

act(() => {
await act(() => {
tree.unmount();
});

Expand Down