首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用wallaby测试时出现意外保留字错误

使用wallaby测试时出现意外保留字错误
EN

Stack Overflow用户
提问于 2016-01-28 21:29:12
回答 2查看 881关注 0票数 7

在我编写测试用例的测试文件中,我导入了一个typescript文件,如下所示:

代码语言:javascript
复制
import {rootReducer} from "../src/reducers/rootReducer";

在rootReducer.ts中,我导入了另一个typescript文件,如下所示:

代码语言:javascript
复制
import taskReducer from "./taskReducer.ts";

然后它会显示错误:

代码语言:javascript
复制
SyntaxError: Unexpected reserved word
at src/reducers/rootReducer.ts:7

rootReducer.ts和taskReducer.ts都位于/src/reducers文件夹下

如果从import语句中删除'.ts‘,则没有失败的测试,但在浏览器中抛出错误。那么应用程序就不会运行了

wallaby配置如下:

代码语言:javascript
复制
module.exports = function (wallaby) {

    return {
        files: [
            'src/*.ts',
            'src/**/*.ts'
        ],

        tests: [
            'test/*Test.ts'
        ],

        testFramework: "mocha",

        env: {
            type: 'node'
        },

        compilers: {
            '**/*.ts': wallaby.compilers.typeScript({
                /* 1 for CommonJs*/
                module: 1
            })
        }
    }
};
EN

回答 2

Stack Overflow用户

发布于 2016-01-28 23:44:13

你的声明:

代码语言:javascript
复制
import taskReducer from "./taskReducer.ts";

应该是:

代码语言:javascript
复制
// Import just taskReducer from this module
import {taskReducer} from "./taskReducer";

或者:

代码语言:javascript
复制
// Import the whole module and call it taskReducer
import * as taskReducer from "./taskReducer";
票数 3
EN

Stack Overflow用户

发布于 2016-02-09 15:32:12

问题不在wallaby.js,而是在你的webpack配置中。要在不指定扩展名的情况下启用需要的文件,您必须添加一个resolve.extensions参数来指定webpack搜索哪些文件:

代码语言:javascript
复制
// webpack.config.js
module.exports = {
  ...
  resolve: {
    // you can now require('file') instead of require('file.ts')
    extensions: ['', '.js', '.ts', '.tsx'] 
  }
};
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35062865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档