Skip to content

Commit a279eab

Browse files
authored
test: test for v3 useCssModule (#750)
Co-authored-by: webfansplz <>
1 parent bc4e0ea commit a279eab

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useCssModule, createApp } from '../../../src'
2+
import { mockWarn } from '../../helpers'
3+
import { proxy } from '../../../src/utils'
4+
5+
function injectStyles(this: any, style: object) {
6+
proxy(this, '$style', {
7+
get: function () {
8+
return style
9+
},
10+
})
11+
}
12+
13+
describe('api: useCssModule', () => {
14+
mockWarn(true)
15+
16+
function mountWithModule(modules: object) {
17+
let res
18+
const Comp = {
19+
beforeCreate() {
20+
injectStyles.call(this, modules)
21+
},
22+
setup() {
23+
res = useCssModule()
24+
},
25+
}
26+
const root = document.createElement('div')
27+
createApp(Comp).mount(root)
28+
return res
29+
}
30+
31+
it('basic usage', () => {
32+
const modules = {
33+
$style: {
34+
red: 'red',
35+
},
36+
}
37+
expect(mountWithModule(modules.$style)).toMatchObject(modules.$style)
38+
})
39+
40+
it('warn out of setup usage', () => {
41+
useCssModule()
42+
expect(
43+
'[Vue warn]: useCssModule must be called inside setup()'
44+
).toHaveBeenWarned()
45+
})
46+
})

0 commit comments

Comments
 (0)