Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Angularjs 之前(防止测试污染)未按预期工作_Angularjs_Testing_Protractor - Fatal编程技术网

Angularjs 之前(防止测试污染)未按预期工作

Angularjs 之前(防止测试污染)未按预期工作,angularjs,testing,protractor,Angularjs,Testing,Protractor,我一直在做AngularJS教程,在一个端到端测试中,我遇到了一个奇怪的问题。作为背景,我目前在。测试代码如下: 'use strict'; /* http://docs.angularjs.org/guide/dev_guide.e2e-testing */ describe('PhoneCat App', function() { describe('Phone list view', function() { beforeEach(function() {

我一直在做AngularJS教程,在一个端到端测试中,我遇到了一个奇怪的问题。作为背景,我目前在。测试代码如下:

'use strict';

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

describe('PhoneCat App', function() {

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

    beforeEach(function() {
      browser.get('app/index.html');
    });

    it('should filter the phone list as user types into the search box', function() {

      var phoneList = element.all(by.repeater('phone in phones'));
      var query = element(by.model('query'));

      expect(phoneList.count()).toBe(3);

      query.sendKeys('nexus');
      expect(phoneList.count()).toBe(1);

      query.clear();

      query.sendKeys('motorola');
      expect(phoneList.count()).toBe(2);
    });
  });

  it('should display current filter value within an element with id "status"', function() {

    var statusElement = element(by.id('status'));
    expect(statusElement.getText()).toMatch(/Current filter:\s*$/);


    element(by.model('query')).sendKeys('nexus');

    expect(statusElement.getText()).toMatch(/Current filter: nexus\s*$/);

  });
});
beforeEach块应该在每次规范执行之前重新加载页面,但似乎不是这样,因为当我使用量角器运行此程序时,插入第一个规范(“motorola”)中查询元素的最后一个文本在执行第二个规范(“motorola”)时仍然存在,导致第二个规范失败


现在,当我将beforeach移动到外部descripe块时,所有规格都成功通过。有什么想法吗

glepretre是正确的。在上面的示例中,您的测试结构如下所示

describe
  describe
    before
    it
  it
由于这种嵌套,before只运行一次,在第一次运行之前。查看每个it块正在测试的内容,我认为它们都是在测试电话列表视图,在这种情况下,正确的嵌套如下所示:

describe
  describe
    before
    it 
    it 
但是,如果索引页不是特定于电话列表视图,而是包含整个应用程序,则可能应该将其加载到顶级描述块中,这是最正确的方法:

describe
  before
  describe
    it
    it

也许是我,但我看不出问题出在哪里:“刷新”应该在每个测试之前的主菜单中(在
description('PhoneCat App')
下)才能正常工作,即在每个测试之间清理条目。从这里的文档中[link][它应该在每个规范之前的两个位置都工作。