Intern is designed exactly to enable these sorts of functional tests in these sorts of situations, and was actually created due to the issue you describe where existing JS test frameworks didn’t enable these sorts of interactions. It includes a functional testing interface that would work like so, assuming app
is on the Node.js side of things, you’d do something like this:
define([ 'intern!bdd', 'intern/chai!expect', 'my/app' ], function (bdd, expect, app) {
var it = bdd.it;
it('should fire appropriate callbacks on start and page reload', function() {
app.start();
return this.remote.get('http://path/to/server')
.then(function () {
expect(app.onStart).toHaveBeenCalled();
})
.refresh()
.then(function () {
expect(app.onRestart).toHaveBeenCalled();
});
});
// ...etc.
});
The Intern tutorial provides a better overview of the difference between unit and functional testing and how to use both. Unlike some other suggestion like CasperJS, it actually will run your functional tests against real browsers, using the standard WebDriver API, in conjunction with a service like Sauce Labs or your own Selenium server.