generated from wednesday-solutions/react-template
-
Notifications
You must be signed in to change notification settings - Fork 13
/
selectors.test.ts
47 lines (42 loc) · 1.55 KB
/
selectors.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { selectHomeContainerDomain, selectLaunchData, selectLaunchListError, selectLoading } from '../selectors';
import { initialState } from '../reducer';
import { RootState } from '@app/configureStore';
import { Launch } from '../types';
describe('HomeContainer selector tests', () => {
let mockedState: RootState;
let launchData: { launches?: Partial<Launch>[] };
let launchListError: Object;
let loading: boolean;
beforeEach(() => {
launchData = { launches: [{}] };
launchListError = 'There was some error while fetching the launch details';
loading = false;
mockedState = {
home: {
launchData,
launchListError,
loading
}
};
});
it('should select the launchListError', () => {
const launchErrorSelector = selectLaunchListError();
expect(launchErrorSelector(mockedState)).toEqual(launchListError);
});
it('should select the global state', () => {
const selector = selectHomeContainerDomain(mockedState);
expect(selector).toEqual(mockedState.home);
});
it('should select the global state from initial state if state.home is not defined', () => {
const selector = selectHomeContainerDomain(initialState);
expect(selector).toEqual(initialState);
});
it('should select loading', () => {
const launchLoadingSelector = selectLoading();
expect(launchLoadingSelector(mockedState)).toEqual(loading);
});
it('should select the launchData', () => {
const launchDataSelector = selectLaunchData();
expect(launchDataSelector(mockedState)).toEqual(launchData);
});
});