Skip to content

Commit

Permalink
test: test for v3 useCssModule (#750)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Jul 7, 2021
1 parent bc4e0ea commit a279eab
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/v3/runtime-core/useCssModule.spec.ts
@@ -0,0 +1,46 @@
import { useCssModule, createApp } from '../../../src'
import { mockWarn } from '../../helpers'
import { proxy } from '../../../src/utils'

function injectStyles(this: any, style: object) {
proxy(this, '$style', {
get: function () {
return style
},
})
}

describe('api: useCssModule', () => {
mockWarn(true)

function mountWithModule(modules: object) {
let res
const Comp = {
beforeCreate() {
injectStyles.call(this, modules)
},
setup() {
res = useCssModule()
},
}
const root = document.createElement('div')
createApp(Comp).mount(root)
return res
}

it('basic usage', () => {
const modules = {
$style: {
red: 'red',
},
}
expect(mountWithModule(modules.$style)).toMatchObject(modules.$style)
})

it('warn out of setup usage', () => {
useCssModule()
expect(
'[Vue warn]: useCssModule must be called inside setup()'
).toHaveBeenWarned()
})
})

0 comments on commit a279eab

Please sign in to comment.