mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Remove ts-ignore flags from previous tests
This commit is contained in:
parent
797cdea7eb
commit
f45cd52c70
@ -100,8 +100,7 @@ it('should log an error if set with a patch different than an object', () => {
|
||||
const [, set] = result.current;
|
||||
expect(mockConsoleError).not.toHaveBeenCalled();
|
||||
|
||||
// @ts-ignore
|
||||
act(() => set('not an object'));
|
||||
act(() => set('not an object' as any));
|
||||
|
||||
expect(mockConsoleError).toHaveBeenCalledTimes(1);
|
||||
expect(mockConsoleError).toHaveBeenCalledWith('useGetSetState setter patch must be an object.');
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { act, renderHook } from '@testing-library/react-hooks';
|
||||
import useMap from '../useMap';
|
||||
|
||||
const setUp = (initialMap?: object) => renderHook(() => useMap(initialMap));
|
||||
const setUp = <T extends object>(initialMap?: T) => renderHook(() => useMap(initialMap));
|
||||
|
||||
it('should init map and utils', () => {
|
||||
const { result } = setUp({ foo: 'bar', a: 1 });
|
||||
@ -28,7 +28,6 @@ it('should get corresponding value for existing provided key', () => {
|
||||
|
||||
let value;
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
value = utils.get('a');
|
||||
});
|
||||
|
||||
@ -36,12 +35,11 @@ it('should get corresponding value for existing provided key', () => {
|
||||
});
|
||||
|
||||
it('should get undefined for non-existing provided key', () => {
|
||||
const { result } = setUp({ foo: 'bar', a: 1 });
|
||||
const { result } = setUp<{ foo: string; a: number; nonExisting?: any }>({ foo: 'bar', a: 1 });
|
||||
const [, utils] = result.current;
|
||||
|
||||
let value;
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
value = utils.get('nonExisting');
|
||||
});
|
||||
|
||||
@ -49,11 +47,10 @@ it('should get undefined for non-existing provided key', () => {
|
||||
});
|
||||
|
||||
it('should set new key-value pair', () => {
|
||||
const { result } = setUp({ foo: 'bar', a: 1 });
|
||||
const { result } = setUp<{ foo: string; a: number; newKey?: number }>({ foo: 'bar', a: 1 });
|
||||
const [, utils] = result.current;
|
||||
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
utils.set('newKey', 99);
|
||||
});
|
||||
|
||||
@ -65,11 +62,10 @@ it('should override current value if setting existing key', () => {
|
||||
const [, utils] = result.current;
|
||||
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
utils.set('foo', 99);
|
||||
utils.set('foo', 'qux');
|
||||
});
|
||||
|
||||
expect(result.current[0]).toEqual({ foo: 99, a: 1 });
|
||||
expect(result.current[0]).toEqual({ foo: 'qux', a: 1 });
|
||||
});
|
||||
|
||||
it('should remove corresponding key-value pair for existing provided key', () => {
|
||||
@ -77,7 +73,6 @@ it('should remove corresponding key-value pair for existing provided key', () =>
|
||||
const [, utils] = result.current;
|
||||
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
utils.remove('foo');
|
||||
});
|
||||
|
||||
@ -85,11 +80,10 @@ it('should remove corresponding key-value pair for existing provided key', () =>
|
||||
});
|
||||
|
||||
it('should do nothing if removing non-existing provided key', () => {
|
||||
const { result } = setUp({ foo: 'bar', a: 1 });
|
||||
const { result } = setUp<{ foo: string; a: number; nonExisting?: any }>({ foo: 'bar', a: 1 });
|
||||
const [, utils] = result.current;
|
||||
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
utils.remove('nonExisting');
|
||||
});
|
||||
|
||||
@ -97,11 +91,10 @@ it('should do nothing if removing non-existing provided key', () => {
|
||||
});
|
||||
|
||||
it('should reset map to initial object provided', () => {
|
||||
const { result } = setUp({ foo: 'bar', a: 1 });
|
||||
const { result } = setUp<{ foo: string; a: number; z?: number }>({ foo: 'bar', a: 1 });
|
||||
const [, utils] = result.current;
|
||||
|
||||
act(() => {
|
||||
// @ts-ignore
|
||||
utils.set('z', 99);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user