Fix unit test error in HostAdd

This commit is contained in:
Marliana Lara
2020-01-23 17:54:06 -05:00
parent b906f8d757
commit 84f056294d

View File

@@ -30,7 +30,7 @@ describe('<HostAdd />', () => {
}); });
test('handleSubmit should post to api', async () => { test('handleSubmit should post to api', async () => {
act(() => { await act(async () => {
wrapper.find('HostForm').prop('handleSubmit')(hostData); wrapper.find('HostForm').prop('handleSubmit')(hostData);
}); });
expect(HostsAPI.create).toHaveBeenCalledWith(hostData); expect(HostsAPI.create).toHaveBeenCalledWith(hostData);
@@ -44,12 +44,14 @@ describe('<HostAdd />', () => {
test('successful form submission should trigger redirect', async () => { test('successful form submission should trigger redirect', async () => {
HostsAPI.create.mockResolvedValueOnce({ HostsAPI.create.mockResolvedValueOnce({
data: { data: {
id: 5,
...hostData, ...hostData,
id: 5,
}, },
}); });
await waitForElement(wrapper, 'button[aria-label="Save"]'); await waitForElement(wrapper, 'button[aria-label="Save"]');
await wrapper.find('HostForm').invoke('handleSubmit')(hostData); await act(async () => {
wrapper.find('HostForm').invoke('handleSubmit')(hostData);
});
expect(history.location.pathname).toEqual('/hosts/5/details'); expect(history.location.pathname).toEqual('/hosts/5/details');
}); });
}); });