I am using Angular's scenarios to do end to end testing of my app. I would like to run tests based on elements that take some time to load. I could just use a sleep()
command, but I'd rather do something like:
whenLoaded('p .foo')
.then(function(elem) { expect(elem.text()).toBe(something); });
Is this possible?
Jasmine.js lets you do that too. Look up async specs.
http://pivotal.github.io/jasmine/
describe("Asynchronous specs", function() {
var value, flag;
it("should support async execution of test preparation and exepectations", function() {
runs(function() {
flag = false;
value = 0;
setTimeout(function() {
flag = true;
}, 500);
});
waitsFor(function() {
value++;
return flag;
}, "The Value should be incremented", 750);
runs(function() {
expect(value).toBeGreaterThan(0);
});
});
});