Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用AngularJS进行Karma茉莉花测试_Javascript_Angularjs_Jasmine_Karma Runner - Fatal编程技术网

Javascript 使用AngularJS进行Karma茉莉花测试

Javascript 使用AngularJS进行Karma茉莉花测试,javascript,angularjs,jasmine,karma-runner,Javascript,Angularjs,Jasmine,Karma Runner,我正在使用Jasmine with Karma为Angular 1.5.7应用程序编写测试 我应该如何从karma.conf.js文件或test main.js文件中引用AngularJS,以确保它可用于我的测试 我目前可以运行单元测试,但当测试引用的文件引用AngularJS(即从“angular”导入AngularJS)时,找不到AngularJS,这表明我需要额外的配置才能使其工作 我正在使用babel传输到ES5,导入转换为RequireJS AMD 错误是: ERROR: 'Ther

我正在使用Jasmine with Karma为Angular 1.5.7应用程序编写测试

我应该如何从
karma.conf.js
文件或
test main.js
文件中引用AngularJS,以确保它可用于我的测试

我目前可以运行单元测试,但当测试引用的文件引用AngularJS(即
从“angular”导入AngularJS
)时,找不到AngularJS,这表明我需要额外的配置才能使其工作

我正在使用babel传输到ES5,导入转换为RequireJS AMD

错误是:

 ERROR: 'There is no timestamp for /base/angular.js!'
如果我将AngularJS添加到
test main.js
的路径部分,则会得到不同的错误:

TypeError: undefined is not an object (evaluating '_angular2.default.module')
如果我从“angular”中删除
导入angular从测试目标语句中,我得到以下错误:

ReferenceError: Can't find variable: angular
My
测试主控灯

var TEST_REGEXP = /(spec|test)\.js$/i;
var allTestFiles = [];

Object.keys(window.__karma__.files).forEach(function(file) {
    if (TEST_REGEXP.test(file)) {
        var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
        allTestFiles.push(normalizedTestModule);
    }
});

var cdn = 'http://localhost:55635/modules/';

require.config({
    baseUrl: '/base',

    initialRequire: [],

    globals: {
        'es6-promise': '3.2.1',
    },

    paths: {
        'lodash': cdn + 'lodash/2.4.1/lodash'
    },

    shim: {},

    deps: allTestFiles,

    callback: window.__karma__.start
});
我的
karma.conf.js

var path = require('path');

module.exports = function(config) {
    'use strict';
    var cdn = 'http://localhost:55635/modules/';
    var basePath = path.dirname(__filename);

    config.set({
        basePath: '',
        frameworks: [
            'requirejs',
            'jasmine'
        ],
        files: [
            {
                pattern: cdn + 'my-lib/version/my-lib.js',
                included: false
            }, 
            {
                pattern: 'test-transpiled/**',
                included: false
            },
            /**
             * This is needed because PhantomJS does not support window.Promise.
             */
            'node_modules/babel-polyfill/dist/polyfill.js',
            'dist/artifacts/my-lib.js',
            'test/unit/test-main.js',
        ],
        proxies: {
            '/cdn/': cdn
        },
        exclude: [],
        preprocessors: {},
        reporters: ['dots'],
        colors: true,
        autoWatch: false,
        singleRun: true,
        browsers: ['PhantomJS'],
    });
};

您是否尝试包括:

'node_modules/angular/angular.js',
'node_modules/angular*/*.js',
在karma.conf.js中的文件数组中

files: [
            {
                pattern: cdn + 'my-lib/version/my-lib.js',
                included: false
            }, 
            {
                pattern: 'test-transpiled/**',
                included: false
            },
            /**
             * This is needed because PhantomJS does not support window.Promise.
             */
            'node_modules/babel-polyfill/dist/polyfill.js',
            'dist/artifacts/my-lib.js',
            'test/unit/test-main.js',

            'node_modules/angular/angular.js',
            'node_modules/angular*/*.js',
        ],
这就是我发现在karma配置中包含所有角度相关性的方法


希望有帮助

您是否尝试包括:

'node_modules/angular/angular.js',
'node_modules/angular*/*.js',
在karma.conf.js中的文件数组中

files: [
            {
                pattern: cdn + 'my-lib/version/my-lib.js',
                included: false
            }, 
            {
                pattern: 'test-transpiled/**',
                included: false
            },
            /**
             * This is needed because PhantomJS does not support window.Promise.
             */
            'node_modules/babel-polyfill/dist/polyfill.js',
            'dist/artifacts/my-lib.js',
            'test/unit/test-main.js',

            'node_modules/angular/angular.js',
            'node_modules/angular*/*.js',
        ],
这就是我发现在karma配置中包含所有角度相关性的方法

希望有帮助