ReferenceError:spyOn未定义Angularjs/Karma/Jasmine

ReferenceError:spyOn未定义Angularjs/Karma/Jasmine,angularjs,jasmine,karma-runner,Angularjs,Jasmine,Karma Runner,我使用Jasmine框架将AngularJS与karma结合使用。我还有其他几个测试正在运行和工作。我的问题是,当我尝试运行此操作时: spyOn(window, 'confirm').and.returnValue(true); 我得到这个错误: ReferenceError: spyOn is not defined 这是我的配置: module.exports = function() { return { basePath: '../', frameworks:

我使用Jasmine框架将AngularJS与karma结合使用。我还有其他几个测试正在运行和工作。我的问题是,当我尝试运行此操作时:

spyOn(window, 'confirm').and.returnValue(true);
我得到这个错误:

ReferenceError: spyOn is not defined
这是我的配置:

module.exports = function() {
  return {
    basePath: '../',
    frameworks: ['jasmine'],
    reporters: ['progress'],
    browsers: ['Chrome_without_security'],
    autoWatch: true,
    // these are default values anyway
    singleRun: false,
    colors: true,
    plugins : [
            'karma-chrome-launcher',
            'karma-jasmine',
            'karma-ng-scenario'
            ],
    customLaunchers: {
      Chrome_without_security: {
        base: 'Chrome',
        flags: ['--disable-web-security']
      }
    },
    files : [
      'static/js/bower_components/angular/angular.js',
      'static/js/app.js',
      'static/js/controllers.js'
    ]
  }
};

var sharedConfig = require('./karma-shared.conf');

module.exports = function(config) {
  var conf = sharedConfig();

  conf.files = conf.files.concat([
    //test files
    './tests/e2e/account/sign-up.js',
    './tests/e2e/account/sign-in.js',
    './tests/e2e/organization/*.js',
    //'./tests/e2e/**/*.js',
    './tests/e2e/account/sign-out.js'
  ]);

  conf.proxies = {
    '/': 'http://localhost/'
  };

  conf.urlRoot = '/__karma__/';

  conf.frameworks = ['ng-scenario'];

  config.set(conf);
};
配置包括e2e测试的共享和特定配置


我有其他一切工作和茉莉被指定为我的因果报应配置框架。有什么想法吗?

在测试脚本中尝试以下方法:

describe('testing spy',function(){
  var window_confirmSpy;

  beforeEach(function(){
    window_confirmSpy = spyOn(window, 'confirm').and.callThrough();
  });

  it('testing windows confirm method',function(){
    window.confirm();

    expect(window_confirmSpy).tohaveBeenCalled();
  });

  it('testing windows confirm method with parameter',function(){
    window.confirm('parameter');

    expect(window_confirmSpy).tohaveBeenCalledWith('parameter');
  });
});

上面的代码片段将确保调用或不调用
window.confirm()

ng场景语法与Jasmine类似,但不完全相同。你确定茉莉花真的上膛了吗?“你是想在单元测试还是集成测试中使用spyOn?”克里斯·卡斯珀,有回应吗?