card.test.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { mount } from '@vue/test-utils'
  2. import { describe, expect, test } from 'vitest'
  3. import Card from '../src/card.vue'
  4. const AXIOM = 'Rem is the best girl'
  5. describe('Card.vue', () => {
  6. test('render test', () => {
  7. const wrapper = mount(() => <Card>{AXIOM}</Card>)
  8. expect(wrapper.text()).toEqual(AXIOM)
  9. })
  10. test('string header', () => {
  11. const header = 'I am header'
  12. const wrapper = mount(() => <Card header={header}>{AXIOM}</Card>)
  13. expect(wrapper.text()).toContain(header)
  14. })
  15. test('vnode header', () => {
  16. const headerCls = 'header-text'
  17. const btnCls = 'test-btn'
  18. const wrapper = mount(() => (
  19. <Card
  20. v-slots={{
  21. default: () => AXIOM,
  22. header: () => (
  23. <div>
  24. <span class={headerCls}>card header</span>
  25. <button class={btnCls}>click me</button>
  26. </div>
  27. ),
  28. }}
  29. />
  30. ))
  31. expect(wrapper.find('.header-text').exists()).toBe(true)
  32. expect(wrapper.find('.test-btn').exists()).toBe(true)
  33. })
  34. test('body style', () => {
  35. const style = 'font-size: 14px;'
  36. const wrapper = mount(() => <Card bodyStyle={style}>{AXIOM}</Card>)
  37. expect(wrapper.find('.el-card__body').attributes('style')).toBe(style)
  38. })
  39. test('body style with object', () => {
  40. const style = { 'font-size': '14px' }
  41. const wrapper = mount(() => <Card bodyStyle={style}>{AXIOM}</Card>)
  42. expect(wrapper.find('.el-card__body').attributes('style')).toBe(
  43. 'font-size: 14px;'
  44. )
  45. })
  46. test('body style with array', () => {
  47. const style = [{ 'font-size': '14px' }, { color: 'blue' }]
  48. const wrapper = mount(() => <Card bodyStyle={style}>{AXIOM}</Card>)
  49. expect(
  50. wrapper.find('.el-card__body').attributes('style')?.replace(/[ ]/g, '')
  51. ).toBe('font-size:14px;color:blue;')
  52. })
  53. test('shadow', () => {
  54. const shadow = 'always'
  55. const wrapper = mount(() => <Card shadow={shadow}>{AXIOM}</Card>)
  56. expect(wrapper.find(`.is-${shadow}-shadow`).exists()).toBe(true)
  57. })
  58. })