Files
react/components/text/__tests__/index.test.tsx
witt 7facec3849 feat(scaleable): add scaleable props to each component (#531)
* feat(scaleable): add scaleable props to each component

* chore(scaleable): update the exported type

* feat: apply scaleable to components

chore: remove with-default

test: improve testcase for scaleable

chore: resolve test warning

ci: upgrade nodejs to latest lts

docs: fix type error in document site

* docs: update documents to be compatible with scaleable

chore: fix build errors

* chore: remove all size-related attributes

docs: improve guide document

* docs: add scaleable documentation

test: update snapshots

chore: remove unused

* feat: add scaleable to grid components

* docs: improve docs

* test: update snapshots

* fix(grid): fix basic component props
2021-08-13 17:10:57 +08:00

84 lines
2.2 KiB
TypeScript

import React from 'react'
import { mount } from 'enzyme'
import { Text } from 'components'
describe('Text', () => {
it('should render P element in the default', () => {
const wrapper = mount(<Text>test-value</Text>)
expect(wrapper.find('p')).not.toBe(0)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with different styles', () => {
const wrapper = mount(
<div>
<Text type="secondary">test-value</Text>
<Text type="success">test-value</Text>
<Text type="warning">test-value</Text>
<Text type="error">test-value</Text>
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('the specified element should be rendered', () => {
const elements = [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'p',
'small',
'span',
'del',
'i',
'em',
'b',
]
const wrapper = mount(
<div>
{elements.map((el, index) => {
const prop = { [el]: true }
return (
<Text {...prop} key={`${el}-${index}`}>
test-value
</Text>
)
})}
</div>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('the combined style should be rendered', () => {
const wrapper = mount(
<Text p b del>
test-value
</Text>,
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should render default color when type missing', () => {
const Mock = Text as any
const wrapper = mount(<Mock type="unknow">test-value</Mock>)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should be able to specify the size of text', () => {
let wrapper = mount(<Text font={14}>test-value</Text>)
expect(wrapper.html()).toMatchSnapshot()
wrapper = mount(<Text font="12rem">test-value</Text>)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
})