2

I'm trying to write a test that checks whether or not an element has a class:

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();
});

The issue is that I keep getting the error TypeError: Cannot read property 'indexOf' of undefined. I expected el.attr('class') to be a future but I'm not sure why it isn't. Is there another way around this?

Ahmed Nuaman
  • 12,662
  • 15
  • 55
  • 87

1 Answers1

0

You need to $digest() your changes before they take effect. Try this:

var el = els.eq(4);

el.click();
scope.$digest();

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

Although much of your code looks far to JQuery-like for an Angular app.

mcv
  • 4,217
  • 6
  • 34
  • 40