-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test for v3 useCssModule (#750)
Co-authored-by: webfansplz <>
- Loading branch information
1 parent
bc4e0ea
commit a279eab
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) |