Skip to content

Commit

Permalink
Merge pull request #490 from sgomes/add-async-tests
Browse files Browse the repository at this point in the history
Add tests for validating asynchronous callbacks.
  • Loading branch information
matthewp committed Jul 17, 2018
2 parents 20aa29b + a2139ca commit 71bb2d8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/tests.js
Expand Up @@ -133,6 +133,19 @@
it('should invoke the matching callback', function() {
expect(called).to.equal(true);
});

it('should invoke the matching async callbacks', function(done) {
page('/async', function(ctx, next) {
setTimeout(function() {
next();
}, 10);
}, function(ctx, next) {
setTimeout(function() {
done();
}, 10);
});
page('/async');
});
});

describe('on redirect', function() {
Expand Down Expand Up @@ -177,6 +190,27 @@
page('/');
});

it('should run async callbacks when exiting the page', function(done) {
var visited = false;
page('/async-exit', function() {
visited = true;
});

page.exit('/async-exit', function(ctx, next) {
setTimeout(function() {
next();
}, 10);
}, function(ctx, next) {
setTimeout(function () {
expect(visited).to.equal(true);
done();
}, 10);
});

page('/async-exit');
page('/');
});

it('should only run on matched routes', function(done) {
page('/should-exit', function() {});
page('/', function() {});
Expand Down

0 comments on commit 71bb2d8

Please sign in to comment.