Skip to content

Commit

Permalink
test: cover
Browse files Browse the repository at this point in the history
  • Loading branch information
rabelloo committed Mar 22, 2021
1 parent e406e50 commit 3b51258
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/react/src/components/field/useField.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { describe, expect, it } from '@jest/globals';
import { describe, expect, it, jest } from '@jest/globals';
import { useContext } from 'react';
import { useForm } from '../form/useForm';
import { FieldProvider, useField } from './useField';

jest.mock('../form/useForm', () => ({ useForm: jest.fn() }));
jest.mock('react', () => {
const context = { Provider: {} };
return {
createContext: () => context,
useContext: () => context,
useContext: jest.fn(() => context),
};
});

Expand All @@ -19,11 +21,14 @@ describe('FieldProvider', () => {
});

describe('useField', () => {
it('should simply wrap useContext', () => {
const context = useContext(null as any);
it('should non-nullish-ly merge form and field state', () => {
const form = { disabled: true, touched: undefined };
(useForm as jest.Mock).mockReturnValueOnce(form);
const field = { disabled: undefined, validity: {} };
(useContext as jest.Mock).mockReturnValueOnce(field);

const result = useField();

expect(result).toBe(context);
expect(result).toStrictEqual({ disabled: true, validity: field.validity });
});
});

0 comments on commit 3b51258

Please sign in to comment.