If we jsx
introduce less
styles in, such as:
import styles from './style.less';
Then jest
when running the unit test, an error will be less
reported in the file, because jest
l is not supported ess
by default. In order to jest
support in less
, we need jest-less-loader
support.
Our first step is to install jest-less-loader
dependencies:
npm install jest-less-loader --save-dev
Then jest.config.js
configure jest-less-loader
the rules:
module.exports = {
transform: {
'^.+\\.js$': 'babel-jest',
'\\.(less|css)$': 'jest-less-loader' // 支持less
},
}
At this time, run j est
for unit testing.