@cainiaofe/cn-ui-m
Version:
40 lines (39 loc) • 2.27 kB
JavaScript
import React from 'react';
import { render } from '@testing-library/react';
import { CnReadOnly } from '../index';
describe('CnReadOnly', function () {
it('将 style 传递给第一个DOM元素', function () {
var style = { color: 'red' };
var container = render(React.createElement(CnReadOnly, { style: style })).container;
expect(container.firstChild).toHaveStyle('color: red');
});
it('将className传递给第一个DOM元素', function () {
var className = 'test-class';
var container = render(React.createElement(CnReadOnly, { className: className })).container;
expect(container.firstChild).toHaveClass('test-class');
});
it('should render children when not empty', function () {
var getByText = render(React.createElement(CnReadOnly, null, "Test")).getByText;
expect(getByText('Test')).toBeInTheDocument();
});
it('should render emptyRender when children is empty', function () {
var getByText = render(React.createElement(CnReadOnly, { emptyRender: function () { return 'Empty'; } })).getByText;
expect(getByText('Empty')).toBeInTheDocument();
});
it('should render default emptyRender when children is empty and no emptyRender prop is provided', function () {
var getByText = render(React.createElement(CnReadOnly, null)).getByText;
expect(getByText('- -')).toBeInTheDocument();
});
it('should add "cn-ui-m-readonly" class by default', function () {
var container = render(React.createElement(CnReadOnly, null)).container;
expect(container.firstChild).toHaveClass('cn-ui-m-readonly');
});
it('should add "cn-ui-m-readonly-ellipsis" class when isOverflowEllipsis prop is true', function () {
var container = render(React.createElement(CnReadOnly, { isOverflowEllipsis: true })).container;
expect(container.firstChild).toHaveClass('cn-ui-m-readonly-ellipsis');
});
it('should not add "cn-ui-m-readonly-ellipsis" class when isOverflowEllipsis prop is false', function () {
var container = render(React.createElement(CnReadOnly, { isOverflowEllipsis: false })).container;
expect(container.firstChild).not.toHaveClass('cn-ui-m-readonly-ellipsis');
});
});