add tests for useSelectableSeasons hook

This commit is contained in:
svetlagasheva 2019-12-16 17:42:49 +02:00
parent dd5e9c803b
commit ad9db5095e

50
tests/hooks.spec.js Normal file
View file

@ -0,0 +1,50 @@
const { renderHook, act } = require('@testing-library/react-hooks');
const useSelectableSeasons = require('../src/routes/MetaDetails/VideosList/useSelectableSeasons');
const videos = [{ 'season': 4 }, { 'season': 5 }, { 'season': 4 }, { 'season': 7 }];
describe('hooks tests', () => {
describe('useSelectableSeasons hook', () => {
it('match 4', async () => {
const { result } = renderHook(() => useSelectableSeasons(videos));
const [, selectedSeason] = result.current;
expect(selectedSeason).toBe(4);
});
it('match 5', async () => {
const { result } = renderHook(() => useSelectableSeasons(videos));
act(() => {
const [, , , selectSeason] = result.current;
selectSeason(5);
});
const [, selectedSeason] = result.current;
expect(selectedSeason).toBe(5);
});
it('not match 6', async () => {
const { result } = renderHook(() => useSelectableSeasons(videos));
act(() => {
const [, , , selectSeason] = result.current;
selectSeason(6);
});
const [, selectedSeason] = result.current;
expect(selectedSeason).toBe(undefined);
});
it('not match $', async () => {
const { result } = renderHook(() => useSelectableSeasons(videos));
act(() => {
const [, , , selectSeason] = result.current;
selectSeason('$');
});
const [, selectedSeason] = result.current;
expect(selectedSeason).toBe(undefined);
});
});
});