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

View File

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