/** * Copyright (c) Paymium. * * This source code is licensed under the MIT license found in the * LICENSE file in the root of this projects source tree. */ import '@testing-library/jest-dom'; import { forwardRef } from 'react'; import { createLabel } from '../index'; import { createLabelMain } from '../Label'; import { LabelInput } from '../LabelInput'; import { createLabelText } from '../LabelText'; import * as allExport from '../index'; const createLabelMainMocked = createLabelMain as unknown as jest.Mock; const createLabelTextMocked = createLabelText as unknown as jest.Mock; const LabelInputMocked = (LabelInput as any) .render as unknown as jest.Mock; jest.mock('../Label'); jest.mock('../LabelInput'); jest.mock('../LabelText'); describe('createLabel', () => { beforeEach(() => { createLabelMainMocked.mockImplementation((e: any) => e); createLabelTextMocked.mockImplementation((e: any) => e); LabelInputMocked.mockImplementation((e: any) => e); }); afterEach(() => { createLabelMainMocked.mockReset(); createLabelTextMocked.mockReset(); LabelInputMocked.mockReset(); }); test('check exports', () => { expect(Object.keys(allExport)).toEqual(['createLabel', 'useLabelContext']); }); test('init', async () => { const Root = forwardRef((p: any, ref: any) =>

); const Text = forwardRef((p: any, ref: any) =>

); const Label = createLabel({ Root, Text, }); expect(createLabelMainMocked).toHaveBeenCalledWith(Root); expect(createLabelTextMocked).toHaveBeenCalledWith(Text); expect(Label).toHaveProperty('displayName', 'Label'); expect(Label.Text).toHaveProperty('displayName', 'Label.Text'); expect(Label.Input).toHaveProperty('displayName', 'Label.Input'); }); });