react-use/tests/misc/hookState.test.ts
xobotyi b6993a6f95
feat(prettier): make prettier a part of eslint.
Also reduce max line width to 100. And remove `lint:types` step for
commit sequence, it bothers when committing incomplete (wip) changes.
2021-02-01 18:58:55 +03:00

35 lines
1.0 KiB
TypeScript

import { resolveHookState } from '../../src/misc/hookState';
describe('resolveHookState', () => {
it('should defined', () => {
expect(resolveHookState).toBeDefined();
});
it(`should return value as is if it's not a function`, () => {
expect(resolveHookState(1)).toBe(1);
expect(resolveHookState('HI!')).toBe('HI!');
expect(resolveHookState(undefined)).toBe(undefined);
});
it('should call passed function', () => {
const spy = jest.fn();
resolveHookState(spy);
expect(spy).toHaveBeenCalled();
});
it('should pass 2nd parameter to function if it awaited', () => {
const spy = jest.fn((n: number) => n);
resolveHookState(spy, 123);
expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0][0]).toBe(123);
});
it('should not pass 2nd parameter to function if it not awaited', () => {
const spy = jest.fn(() => {});
/* @ts-expect-error */
resolveHookState(spy, 123);
expect(spy).toHaveBeenCalled();
expect(spy.mock.calls[0].length).toBe(0);
});
});