Skip to content

Commit 1e086d9

Browse files
author
Ray Schamp
committed
Improve ProjectFetcherHOC test
This ensures that the reducer is actually called with the project data that storage loaded
1 parent 616281e commit 1e086d9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/unit/util/project-fetcher-hoc.test.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ describe('ProjectFetcherHOC', () => {
3535
expect(mockSetProjectIdFunc.mock.calls[0][0]).toBe('100');
3636
});
3737
test('when there is a reduxProjectId and isFetchingWithProjectId is true, it loads the project', () => {
38+
const mockedOnFetchedProject = jest.fn();
3839
const originalLoad = storage.load;
3940
storage.load = jest.fn((type, id) => Promise.resolve({data: id}));
4041
const Component = ({projectId}) => <div>{projectId}</div>;
4142
const WrappedComponent = ProjectFetcherHOC(Component);
42-
const mounted = mountWithIntl(<WrappedComponent store={store} />);
43+
const mounted = mountWithIntl(
44+
<WrappedComponent
45+
store={store}
46+
onFetchedProjectData={mockedOnFetchedProject}
47+
/>
48+
);
4349
mounted.setProps({
4450
reduxProjectId: '100',
4551
isFetchingWithId: true,
@@ -49,5 +55,10 @@ describe('ProjectFetcherHOC', () => {
4955
storage.AssetType.Project, '100', storage.DataFormat.JSON
5056
);
5157
storage.load = originalLoad;
58+
// nextTick needed since storage.load is async, and onFetchedProject is called in its then()
59+
process.nextTick(
60+
() => expect(mockedOnFetchedProject)
61+
.toHaveBeenLastCalledWith('100', LoadingState.FETCHING_WITH_ID)
62+
);
5263
});
5364
});

0 commit comments

Comments
 (0)