Writing Jasmine Unit Tests In ES6

Posted xiaobin-hlj80

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Writing Jasmine Unit Tests In ES6相关的知识,希望对你有一定的参考价值。

1. package.json

{
  "scripts": {
    "tests": "karma start"
  },
  "devDependencies": {
    "babel-loader": "^7.1.4",
    "webpack": "^4.12.0",
    "jasmine-core": "^3.1.0",
    "karma": "^2.0.4",
    "karma-jasmine": "^1.1.2",
    "jasmine": "^3.1.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-webpack": "^3.0.0"
  }
}

2. karma.config.js

module.exports = function(config) {
    config.set({
        browsers: [‘PhantomJS‘],
        files: [
            { pattern: ‘test-context.js‘, watched: false }
        ],
        frameworks: [‘jasmine‘],
        preprocessors: {
            ‘test-context.js‘: [‘webpack‘]
        },
        webpack: {
            module: {
                loaders: [
                    { test: /.js/, exclude: /node_modules/, loader: ‘babel-loader‘ }
                ]
            },
            watch: true
        },
        webpackServer: {
            noInfo: true
        }
    });
};

 

3. test-context.js

var context = require.context(‘./spec‘, true, /.spec.js$/);
context.keys().forEach(context);

 

Reference:

http://www.syntaxsuccess.com/viewarticle/writing-jasmine-unit-tests-in-es6

 

以上是关于Writing Jasmine Unit Tests In ES6的主要内容,如果未能解决你的问题,请参考以下文章

在Jasmine Unit Test中为PhantomJS配置浏览器语言

如何使用Jasmine Unit测试测试私有方法

[Unit Testing] Jasmine Spies

如何为combineLatest rxjs Angular编写Jasmine Unit测试用例

生存还是毁灭

使用 Jasmine 进行 Angular2 测试,mouseenter/mouseleave-test