Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created February 1, 2012 19:46
Show Gist options
  • Save vojtajina/1718884 to your computer and use it in GitHub Desktop.
Save vojtajina/1718884 to your computer and use it in GitHub Desktop.
Angular: Scenario navigate to future url
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/build/angular-scenario.js" ng:autotest></script>
<script type="text/javascript">
// this is just copy of browser().navigateTo()
// the only difference is this implementation accepts future value
angular.scenario.dsl('goToFutureUrl', function() {
return function(futureUrl) {
var application = this.application;
return this.addFuture("browser navigate to future url", function(done) {
// we do navigate to futureUrl.value, which was undefined at the time of "recording"
application.navigateTo(futureUrl.value, function() {
done(null, futureUrl.value);
}, done);
});
};
});
angular.scenario.dsl('whereToGo', function() {
return function(a, b) {
return this.addFutureAction('deciding where to go (' + a + ' or ' + b + ')',
function($window, $document, done) {
// randomly sets a or b (just stupid example, don't think you want a randomness in a test)
var decidedUrl = Math.random() > 0.5 ? a : b;
done(null, decidedUrl);
});
};
});
describe('just a test', function() {
beforeEach(function() {
browser().navigateTo('testCase.html');
});
it('should randomly fail', function() {
expect(whereToGo('/a.html', '/b.html')).toEqual('/a.html');
});
it('should go to url based on whereToGo', function() {
// it will navigate to either /a.html or /b.html
goToFutureUrl(whereToGo('/a.html', '/b.html'));
});
});
</script>
<title></title>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment