我有一个模块,我想为其编写测试。我使用 webpack 来转译它,因为我是用 ES6 编写的。
文件(app.js)如下所示:
import template from './app.html'; // pulls in the template for this component
import './app.scss'; // pulls in the styles for this component
但是当我运行测试时,我收到一个错误,找不到 app.scss
ERROR in ./src/app.js
Module not found: Error: Cannot resolve module 'scss' in /Users/.../src
@ ./src/app.js 11:0-21
13 05 2016 10:38:52.276:INFO [..browserinfo..]: Connected on socket /#KYFiNbOR-7lqgc9qAAAA with id 63011795
(browser) ERROR
Uncaught Error: Cannot find module "./app.scss"
at /Users/.../spec.bundle.js:34081 <- webpack:///src/app.js:4:0
Finished in 0.241 secs / 0 s
测试是这样开始的:
import angular from 'angular';
import header from './app.js'; // error occurs here cause .scss file is not recognized
describe('my module', () => {
let $rootScope, makeController;
// testing stuff
});
我的 karma.conf.js 文件包含以下内容:
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.js/, exclude: [/app\/lib/, /node_modules/], loader: 'babel' },
{ test: /\.html/, loader: 'raw' },
{ test: /\.scss/, loader: 'style!css!scss' },
{ test: /\.css$/, loader: 'style!css' }
]
}
}
如何让 karma/webpack 正确读取 scss 文件并运行我的测试?
最佳答案
问题是一个拼写错误:
scss
应该是 sass
webpack: {
module: {
loaders: [
...,
{ test: /\.scss/, loader: 'style!css!sass' },
...
]
}
}
关于javascript - Karma - 找不到模块 : Error: Cannot resolve module 'scss' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37214361/