search

Home  >  Q&A  >  body text

javascript - vue official example code, when processing scss files during unit testing, an error is reported

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

高洛峰高洛峰2769 days ago517

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 11:01:10

    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

    reply
    0
  • Cancelreply