mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
35 lines
1.0 KiB
TypeScript
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);
|
|
});
|
|
});
|