test(gradient-text): add gradient-text test (#368)

* test(gradient-text): add gradient-text test

* test: optimization

* test: optimization
This commit is contained in:
XieZongChen 2021-07-04 00:20:30 +08:00 committed by GitHub
parent 0c2489e0a2
commit 47a67a2da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View File

@ -5,4 +5,57 @@ describe('n-gradient-text', () => {
it('should work with import on demand', () => {
mount(NGradientText)
})
it('should work with `type` prop', async () => {
const wrapper = mount(NGradientText, { slots: { default: () => 'test' } })
expect(wrapper.find('.n-gradient-text').text()).toContain('test')
const typeArray = [
'error',
'info',
'warning',
'success',
'primary'
] as const
typeArray.forEach((item) => {
const wrapper = mount(NGradientText, {
props: { type: item },
slots: { default: () => 'test' }
})
expect(wrapper.find('.n-gradient-text').classes()).toContain(
`n-gradient-text--${item}-type`
)
})
})
it('should work with `size` prop', async () => {
const wrapper = mount(NGradientText, { slots: { default: () => 'test' } })
expect(wrapper.find('.n-gradient-text').attributes('style')).not.toContain(
'font-size'
)
await wrapper.setProps({ size: '24' })
expect(wrapper.find('.n-gradient-text').attributes('style')).toContain(
'font-size: 24px;'
)
})
it('should work with `gradient` prop', async () => {
const wrapper = mount(NGradientText, { slots: { default: () => 'test' } })
await wrapper.setProps({
gradient:
"{ deg: 180, from: 'rgb(85, 85, 85)', to: 'rgb(170, 170, 170)' }"
})
expect(
wrapper.find('.n-gradient-text').attributes('style')
).toMatchSnapshot()
await wrapper.setProps({
gradient: 'linear-gradient(90deg, red 0%, green 50%, blue 100%)'
})
expect(
wrapper.find('.n-gradient-text').attributes('style')
).toMatchSnapshot()
})
})

View File

@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`n-gradient-text should work with \`gradient\` prop 1`] = `"--bezier: cubic-bezier(.4, 0, .2, 1); --rotate: 252deg; --color-start: rgba(24, 160, 88, 0.6); --color-end: #18a058; --font-weight: 500;"`;
exports[`n-gradient-text should work with \`gradient\` prop 2`] = `"--bezier: cubic-bezier(.4, 0, .2, 1); --rotate: 252deg; --color-start: rgba(24, 160, 88, 0.6); --color-end: #18a058; --font-weight: 500;"`;