Fixes console errors thrown about React state updates being be wrapped into act(...) on the inventory form

This commit is contained in:
mabashian
2020-07-28 12:05:02 -04:00
parent 7e8d0b5883
commit 1faaba4e6c
2 changed files with 21 additions and 13 deletions

View File

@@ -51,12 +51,14 @@ describe('<InventoryAdd />', () => {
]; ];
await waitForElement(wrapper, 'isLoading', el => el.length === 0); await waitForElement(wrapper, 'isLoading', el => el.length === 0);
await act(async () => {
wrapper.find('InventoryForm').prop('onSubmit')({ wrapper.find('InventoryForm').prop('onSubmit')({
name: 'new Foo', name: 'new Foo',
organization: { id: 2 }, organization: { id: 2 },
insights_credential: { id: 47 }, insights_credential: { id: 47 },
instanceGroups, instanceGroups,
}); });
});
await sleep(1); await sleep(1);
expect(InventoriesAPI.create).toHaveBeenCalledWith({ expect(InventoriesAPI.create).toHaveBeenCalledWith({
name: 'new Foo', name: 'new Foo',
@@ -74,7 +76,9 @@ describe('<InventoryAdd />', () => {
test('handleCancel should return the user back to the inventories list', async () => { test('handleCancel should return the user back to the inventories list', async () => {
await waitForElement(wrapper, 'isLoading', el => el.length === 0); await waitForElement(wrapper, 'isLoading', el => el.length === 0);
await act(async () => {
wrapper.find('Button[aria-label="Cancel"]').simulate('click'); wrapper.find('Button[aria-label="Cancel"]').simulate('click');
});
expect(history.location.pathname).toEqual('/inventories'); expect(history.location.pathname).toEqual('/inventories');
}); });
}); });

View File

@@ -102,7 +102,9 @@ describe('<InventoryEdit />', () => {
test('handleCancel returns the user to inventory detail', async () => { test('handleCancel returns the user to inventory detail', async () => {
await waitForElement(wrapper, 'isLoading', el => el.length === 0); await waitForElement(wrapper, 'isLoading', el => el.length === 0);
await act(async () => {
wrapper.find('Button[aria-label="Cancel"]').simulate('click'); wrapper.find('Button[aria-label="Cancel"]').simulate('click');
});
expect(history.location.pathname).toEqual( expect(history.location.pathname).toEqual(
'/inventories/inventory/1/details' '/inventories/inventory/1/details'
); );
@@ -114,6 +116,7 @@ describe('<InventoryEdit />', () => {
{ name: 'Bizz', id: 2 }, { name: 'Bizz', id: 2 },
{ name: 'Buzz', id: 3 }, { name: 'Buzz', id: 3 },
]; ];
await act(async () => {
wrapper.find('InventoryForm').prop('onSubmit')({ wrapper.find('InventoryForm').prop('onSubmit')({
name: 'Foo', name: 'Foo',
id: 13, id: 13,
@@ -121,6 +124,7 @@ describe('<InventoryEdit />', () => {
insights_credential: { id: 13 }, insights_credential: { id: 13 },
instanceGroups, instanceGroups,
}); });
});
await sleep(0); await sleep(0);
instanceGroups.map(IG => instanceGroups.map(IG =>
expect(InventoriesAPI.associateInstanceGroup).toHaveBeenCalledWith( expect(InventoriesAPI.associateInstanceGroup).toHaveBeenCalledWith(