import {renderHook} from '@testing-library/react';
import {useFilterField} from '.';
import {act} from 'react-dom/test-utils';

describe('useFilterField', function () {
  it('声明', function () {
    expect(useFilterField).toBeDefined();
    expect(useFilterField).toBeInstanceOf(Function);
  });

  it('返回值', function () {
    const {result} = renderHook(function () {
      return useFilterField({name: '', age: 0});
    });

    expect(result.current[0]).toEqual({name: '', age: 0});
    expect(result.current[1]).toBeInstanceOf(Function);

    act(() => result.current[1]('name')('simon'));
    expect(result.current[0]).toEqual({name: 'simon', age: 0});

    act(() => result.current[1]('age')(12));
    expect(result.current[0]).toEqual({name: 'simon', age: 12});
  });
});
