AngularJS scenarios expect class and futures

163 views Asked by At

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?

1

There are 1 answers

0
mcv On

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.