Skip to content

Commit b646fa9

Browse files
author
YiSiWang
committed
add test
1 parent 123f4e2 commit b646fa9

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

test/fixtures/css-modules.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<style module="style">
2+
.red {
3+
color: red;
4+
}
5+
@keyframes fade {
6+
from { opacity: 1; } to { opacity: 0; }
7+
}
8+
.animate {
9+
animation: fade 1s;
10+
}
11+
</style>
12+
13+
<style scoped lang="stylus" module>
14+
.red
15+
color: red
16+
</style>
17+
18+
<script>
19+
module.exports = {}
20+
</script>

test/test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,37 @@ describe('vue-loader', function () {
377377
done()
378378
})
379379
})
380+
381+
it('css-modules', function (done) {
382+
test({
383+
entry: './test/fixtures/css-modules.vue'
384+
}, function (window) {
385+
var module = window.vueModule
386+
387+
// get local class name
388+
var className = module.computed.style().red
389+
expect(className).to.match(/^_/)
390+
391+
// class name in style
392+
var style = [].slice.call(window.document.querySelectorAll('style')).map(function (style) {
393+
return style.textContent
394+
}).join('\n')
395+
expect(style).to.contain('.' + className + ' {\n color: red;\n}')
396+
397+
// animation name
398+
var match = style.match(/@keyframes\s+(\S+)\s+{/)
399+
expect(match).to.have.length(2)
400+
var animationName = match[1]
401+
expect(animationName).to.not.equal('fade')
402+
expect(style).to.contain('animation: ' + animationName + ' 1s;')
403+
404+
// default module + pre-processor + scoped
405+
var anotherClassName = module.computed.$style().red
406+
expect(anotherClassName).to.match(/^_/).and.not.equal(className)
407+
var id = '_v-' + hash(require.resolve('./fixtures/css-modules.vue'))
408+
expect(style).to.contain('.' + anotherClassName + '[' + id + ']')
409+
410+
done()
411+
})
412+
})
380413
})

0 commit comments

Comments
 (0)