dominator.js
dominator.js copied to clipboard
Support for single page web-apps
I started using Dominator to test a single-page webapp (actually a PhoneGap app). My setup looks like:
dominator.load({ src: 'http://localhost:4567' ... });
Now each test can start navigating, which is just clicking and rendering views within the one page.
Currently it seems that the open
function really expects physical pages. Is would be great if we could also pass it an absolute URL, so that each test can simply reset the entire app and start fresh. My current workaround is:
var HOME = 'http://localhost:4567';
dominator.extend('home', function(callback) {
this.window.location.href = HOME;
this.expect(1);
var intervalId = setInterval(function() {
if (this.window && this.window.location.href.indexOf(HOME) >= 0) {
QUnit.ok(true, HOME + ' loaded');
clearTimeout(intervalId);
callback();
}
}, 100);
});
So each test can do:
[TEST 1] dominator.home().click('foo') ...
[TEST 2] dominator.home().click('bar') ...
// home() doesn't take any argument for simplicity reasons.
// Ideally it would just reset to whatever URL the iframe was created with.
Is there an easier way I'm missing, or does that functionality make sense?
Cheers