Skip to content

Commit

Permalink
fix: useCSSModule to adapt the change of getCurrentInstance, close #620
Browse files Browse the repository at this point in the history
… (#622)

* fix(useCssModule): adapting the behavior of `useCSSModule` to the change of `getCurrentInstance`. close #620

* chores: add test for `useCssModule`.
  • Loading branch information
Trendymen committed Jan 5, 2021
1 parent 4b2f1ab commit 2ddead0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/apis/useCssModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useCSSModule = (name = '$style'): Record<string, string> => {
return EMPTY_OBJ
}

const mod = (instance as any)[name]
const mod = (instance.proxy as any)?.[name]
if (!mod) {
__DEV__ &&
warn(`Current instance does not have CSS module named "${name}".`)
Expand Down
31 changes: 31 additions & 0 deletions test/apis/useCssModule.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Vue = require('vue/dist/vue.common.js')
const { useCSSModule } = require('../../src')

const style = { whateverStyle: 'whateverStyle' }

function injectStyles() {
Object.defineProperty(this, '$style', {
configurable: true,
get: function () {
return style
},
})
}

describe('api/useCssModule', () => {
it('should get the same object', (done) => {
const vm = new Vue({
beforeCreate() {
injectStyles.call(this)
},
template: '<div>{{style}}</div>',
setup() {
const style = useCSSModule()
return { style }
},
})
vm.$mount()
expect(vm.style).toBe(style)
done()
})
})

0 comments on commit 2ddead0

Please sign in to comment.