Skip to content

Commit

Permalink
✅ test: 添加测试
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Apr 18, 2021
1 parent 65e5877 commit 2496ea3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`FloatLabelInput 1`] = `
exports[`FloatLabelInput 正常渲染 1`] = `
<div>
<div>
<div
class="avx-float-input-container"
data-testid="container"
>
<input
class="ant-input"
data-testid="input"
label="test"
type="text"
value=""
/>
<label
class=""
class="avx-float-input-label"
data-testid="label"
style="margin-left: 8px; margin-top: -26px;"
>
test
Expand Down
38 changes: 34 additions & 4 deletions packages/float-label-input/tests/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
import React from 'react';
import { render } from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';

import FloatLabelInput from '@arvinxu/float-label-input';

test('FloatLabelInput', () => {
const { container } = render(<FloatLabelInput label={'test'} />);
expect(container).toMatchSnapshot();
describe('FloatLabelInput', () => {
it('正常渲染', () => {
const { container } = render(<FloatLabelInput label={'test'} />);
expect(container).toMatchSnapshot();
});

it('受控组件', () => {
// const { container } = render(<FloatLabelInput label={'test'} />);
});

it('focus 向上移动; blur 返回', () => {
const { queryByTestId } = render(<FloatLabelInput label={'test'} />);

const input = queryByTestId('input');
const label = queryByTestId('label');

expect(label.style.transform).toBe('');
fireEvent.focus(input);
expect(label.style.transform).toBe('translateY(-28px)');
fireEvent.blur(input);
expect(label.style.transform).toBe('');
});

it('可输入外部高度', () => {
// const { queryByTestId } = render(
// <FloatLabelInput label={'test'} style={{ height: 40 }} />,
// );
// const input = queryByTestId('input');
// fireEvent.focus(input);
// const label = queryByTestId('label');
// debug(label);
// expect(label.style.transform).toBe('translateY(-32px)');
});
});

0 comments on commit 2496ea3

Please sign in to comment.