【问题标题】:AngularJS scenarios expect class and futuresAngularJS 场景期望类和期货
【发布时间】:2013-06-19 13:03:53
【问题描述】:

我正在尝试编写一个测试来检查元素是否具有类:

element('#header-menu .menu-component-item a').query(function(els, done) {
  var el = els.eq(4);

  el.click();
  sleep(.25);

  expect(browser().location().path()).toBe(el.attr('href'));
  expect(el.attr('class')).toContain('selected');
  done();
});

问题是我不断收到错误TypeError: Cannot read property 'indexOf' of undefined。我希望el.attr('class') 成为未来,但我不确定为什么不是。有没有其他方法可以解决这个问题?

【问题讨论】:

    标签: angularjs angular-scenario


    【解决方案1】:

    您需要$digest()您的更改才能生效。试试这个:

    var el = els.eq(4);
    
    el.click();
    scope.$digest();
    
    expect(browser().location().path()).toBe(el.attr('href'));
    expect(el.attr('class')).toContain('selected');
    

    尽管对于 Angular 应用程序而言,您的大部分代码看起来与 JQuery 相去甚远。

    【讨论】:

      猜你喜欢
      • 2021-09-17
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      • 2019-03-23
      相关资源
      最近更新 更多