Jest supports less

If we jsxintroduce lessstyles in, such as:

import styles from './style.less';

Then jestwhen running the unit test, an error will be lessreported in the file, because jestl is not supported essby default. In order to jestsupport in less, we need jest-less-loadersupport.

Our first step is to install jest-less-loaderdependencies:

npm install jest-less-loader --save-dev

Then jest.config.jsconfigure jest-less-loaderthe rules:

module.exports = {
    
    
	transform: {
    
    
		'^.+\\.js$': 'babel-jest',
		'\\.(less|css)$': 'jest-less-loader' // 支持less
	},
}

At this time, run j estfor unit testing.

おすすめ

転載: blog.csdn.net/weixin_50096821/article/details/123808064