我正在尝试使用grunt karma和karma-typecript-preprocessor自动执行单元测试。使用karma-typescript-preprocessor插件发现错误'找不到名字......'
但是,当我运行'grunt watch'时,karma输出以下错误: ERROR [preprocessor.typescript]:/home/loic/Code/appName/src/app/app.spec.ts.ktp.ts (15,13):错误TS2304:找不到名字'expect'。
发生此错误有很多名字:“形容,角度,期望”等
奇怪的是,当我运行命令行‘TSC /path/to/app.spec.ts’,新的js文件被创建,没有错误。
下面我karma.conf.js:
module.exports = function (karma) {
karma.set({
/**
* From where to look for files, starting with the location of this file.
*/
basePath: '../',
typescriptPreprocessor: {
// options passed to the typescript compiler
options: {
sourceMap: false, // (optional) Generates corresponding .map file.
target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd'
noImplicitAny: false, // (optional) Warn on expressions and declarations with an implied 'any' type.
noResolve: true, // (optional) Skip resolution and preprocessing.
removeComments: true // (optional) Do not emit comments to output.
},
// transforming the filenames
transformPath: function(path) {
return path.replace(/\.ts$/, '.js');
}
},
/**
* This is the list of file patterns to load into the browser during testing.
*/
files: [
<% scripts.forEach(function (file) { %>'<%= file %>',
<% }); %>
'src/**/*.ts'
],
exclude: [
'src/assets/**/*.ts',
'src/typeScript/**/*.ts'
],
frameworks: [ 'jasmine' ],
plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-typescript-preprocessor' ],
preprocessors: {
'**/*.ts': 'typescript'
},
/**
* How to report, by default.
*/
reporters: 'dots',
/**
* On which port should the browser connect, on which port is the test runner
* operating, and what is the URL path for the browser to use.
*/
port: 9018,
runnerPort: 9100,
urlRoot: '/',
/**
* Disable file watching by default.
*/
autoWatch: false,
/**
* The list of browsers to launch to test on. This includes only "Firefox" by
* default, but other browser names include:
* Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
*
* Note that you can also use the executable name of the browser, like "chromium"
* or "firefox", but that these vary based on your operating system.
*
* You may also leave this blank and manually navigate your browser to
* http://localhost:9018/ when you're running tests. The window/tab can be left
* open and the tests will automatically occur there during the build. This has
* the aesthetic advantage of not launching a browser every time you save.
*/
browsers: [
'Firefox'
]
});
};
任何帮助,将不胜感激
这一个固定的我的问题。 –