angularjs - browser() 对象在哪里定义在 angularJS 中?

标签 angularjs karma-runner

按照 Angular-phonecat 教程,scenario.js 中的第 7 步使用了 browser() 和 binding() 对象,但是,当我尝试使用它们来测试我的应用程序时,运行 testacular 说:

ReferenceError: browser is not defined
        at null.<anonymous> 

Intellij Ideal 还说:未解析的函数或方法 browser()。我在这里错过了什么?

这里是教程中的代码片段: '使用严格';

/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */

describe('PhoneCat App', function() {

  it('should redirect index.html to index.html#/phones', function() {
    browser().navigateTo('../../app/index.html');
    expect(browser().location().url()).toBe('/phones');
  });


  describe('Phone list view', function() {

    beforeEach(function() {
      browser().navigateTo('../../app/index.html#/phones'); //<---  browser() object is not defined !!! 
    });


    it('should filter the phone list as user types into the search box', function() {
      expect(repeater('.phones li').count()).toBe(20);

      input('query').enter('nexus');
      expect(repeater('.phones li').count()).toBe(1);

      input('query').enter('motorola');
      expect(repeater('.phones li').count()).toBe(8);
    });


    it('should be possible to control phone order via the drop down select box', function() {
      input('query').enter('tablet'); //let's narrow the dataset to make the test assertions shorter

      expect(repeater('.phones li', 'Phone List').column('phone.name')).
          toEqual(["Motorola XOOM\u2122 with Wi-Fi",
                   "MOTOROLA XOOM\u2122"]);

      select('orderProp').option('Alphabetical');

      expect(repeater('.phones li', 'Phone List').column('phone.name')).
          toEqual(["MOTOROLA XOOM\u2122",
                   "Motorola XOOM\u2122 with Wi-Fi"]);
    });


    it('should render phone specific links', function() {
      input('query').enter('nexus');
      element('.phones li a').click();
      expect(browser().location().url()).toBe('/phones/nexus-s');
    });
  });


  describe('Phone detail view', function() {

    beforeEach(function() {
      browser().navigateTo('../../app/index.html#/phones/nexus-s');
    });


    it('should display placeholder page with phoneId', function() {
      expect(binding('phoneId')).toBe('nexus-s');
    });
  });
});

最佳答案

它在 angular-scenario.js 中定义

关于angularjs - browser() 对象在哪里定义在 angularJS 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13754336/

相关文章:

angularjs - 与兄弟指令沟通

javascript - 错误 : [$controller:ctrlreg] after declaring controller?

teamcity - 如何将 Karma 与 TeamCity 集成

angularjs - 如何在指令 [jasmine] 中访问 Controller

javascript - 如何以编程方式 ng-bind svg 元素上的属性?

javascript - 使用 Promise 更新 Json 值

javascript - 如何在其他地方使用 $http.get 的响应

angularjs - 如何模拟提供商

google-chrome - Karma 无法捕获 Chrome v93 并超时/放弃

javascript - 在 Karma 中动态加载 JavaScript 文件