javascript - vue official example code, when processing scss files during unit testing, an error is reported
高洛峰
高洛峰 2017-05-18 10:59:10
0
1
474

The project is generated using vue init webpack my-project, which is the vue webpack template

Add bootstrap scss package
Add
import './style/bootstrap.scss';

to the main.js file

npm run dev and npm run build are both normal

But when npm run unit reports an error, a lot of errors appear similar to
font-size: $font-size-small;

        ^
  Undefined variable: "$font-size-small".

mistake

I’m very confused:
1 Why the unit test alone reports an error
2 Try to remove the added import './style/bootstrap.scss'; in main.js, the page coming out of npm run dev has no style , but the npm run unit error is still

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
洪涛

There is the following statement in test/unit/index.js
// require all src files except main.js for coverage.
// you can also change this to match only the subset of files that
// you want coverage for .
const srcContext = require.context('../../src', true, /^./(?!main(.js)?$)/)

Changed to
const srcContext = require.context('../../src', true, /^./(style$)/)

Problem Solved

It should be that in order to test the code coverage, karma originally loaded all files except main.js. I removed the style instead

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!