useCssModule.spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { h, nodeOps, render } from '@vue/runtime-test'
  2. import { useCssModule } from '../../src/helpers/useCssModule'
  3. describe('useCssModule', () => {
  4. function mountWithModule(modules: any, name?: string) {
  5. let res
  6. render(
  7. h({
  8. render() {},
  9. __cssModules: modules,
  10. setup() {
  11. res = useCssModule(name)
  12. },
  13. }),
  14. nodeOps.createElement('div'),
  15. )
  16. return res
  17. }
  18. test('basic usage', () => {
  19. const modules = {
  20. $style: {
  21. red: 'red',
  22. },
  23. }
  24. expect(mountWithModule(modules)).toMatchObject(modules.$style)
  25. })
  26. test('basic usage', () => {
  27. const modules = {
  28. foo: {
  29. red: 'red',
  30. },
  31. }
  32. expect(mountWithModule(modules, 'foo')).toMatchObject(modules.foo)
  33. })
  34. test('warn out of setup usage', () => {
  35. useCssModule()
  36. expect('must be called inside setup').toHaveBeenWarned()
  37. })
  38. test('warn missing injection', () => {
  39. mountWithModule(undefined)
  40. expect('instance does not have CSS modules').toHaveBeenWarned()
  41. })
  42. test('warn missing injection', () => {
  43. mountWithModule({ $style: { red: 'red' } }, 'foo')
  44. expect('instance does not have CSS module named "foo"').toHaveBeenWarned()
  45. })
  46. })