diff --git a/test/enterexit.mocha.js b/test/enterexit.mocha.js new file mode 100644 index 0000000..b2bfe8f --- /dev/null +++ b/test/enterexit.mocha.js @@ -0,0 +1,68 @@ +var expect, router, tracks; + +expect = require('expect.js'); + +global.window = { + location: {}, + history: {} +}; + +tracks = require('../lib/browser'); + +router = require('../lib/router'); + +describe('enter/exit', function() { + it('enter should not trigger change in params', function(done) { + var app, createPage, history, onRoute, options, routes, check; + this.timeout(2000); + app = {}; + createPage = function(req, res) { + return { + model: {} + , params: { + url: '/b' + } + }; + }; + onRoute = function(callback, page, params, next, isTransitional, done) { + expect(page.params.url).to.be.equal('/b'); + return done(); + }; + routes = tracks.setup(app, createPage, onRoute); + app.enter('/a', function() {}); + history = app.history; + options = { + method: 'enter' + , url: '/a' + , noNavigate: true + } + return router.render(history.page(), options); + }); + + return it('exit should not trigger change in params', function(done) { + var app, createPage, history, onRoute, options, routes, check; + this.timeout(2000); + app = {}; + createPage = function(req, res) { + return { + model: {} + , params: { + url: '/b' + } + }; + }; + onRoute = function(callback, page, params, next, isTransitional, done) { + expect(page.params.url).to.be.equal('/b'); + return done(); + }; + routes = tracks.setup(app, createPage, onRoute); + app.exit('/a', function() {}); + history = app.history; + options = { + method: 'exit' + , url: '/a' + , noNavigate: true + } + return router.render(history.page(), options); + }); +}); diff --git a/test/mocha.opts b/test/mocha.opts index b1c3a55..119013b 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -3,4 +3,3 @@ --timeout 500 --growl --debug ---compilers coffee:coffee-script diff --git a/test/transitional.mocha.coffee b/test/transitional.mocha.coffee deleted file mode 100644 index 9d249c9..0000000 --- a/test/transitional.mocha.coffee +++ /dev/null @@ -1,39 +0,0 @@ -expect = require 'expect.js' - -global.window = - location: {} - history: {} - -tracks = require '../lib/browser' -router = require '../lib/router' - - -describe 'transitional routes', -> - it 'should parse an empty query params when going from -> to, when no querystring in the url', (done) -> - @timeout 2000 - app = {} - createPage = (req, res) -> - return {model: {}} - onRoute = (callback, page, params, next, isTransitional, done) -> - if isTransitional - if callback.length is 4 - callback(page.model, params, next, done) - return true - else - callback(page.model, params, next) - return - callback(page, page.model, params, next) - - routes = tracks.setup app, createPage, onRoute - - app.get from: '/a/b', to: '/x/y', (model, params, next) -> - expect(params.query).to.eql {} - done() - - history = app.history - options = - method: 'get' - url: '/x/y' - previous: '/a/b' - body: '' - router.render(history.page(), options) diff --git a/test/transitional.mocha.js b/test/transitional.mocha.js new file mode 100644 index 0000000..59e34d1 --- /dev/null +++ b/test/transitional.mocha.js @@ -0,0 +1,53 @@ +var expect, router, tracks; + +expect = require('expect.js'); + +global.window = { + location: {}, + history: {} +}; + +tracks = require('../lib/browser'); + +router = require('../lib/router'); + +describe('transitional routes', function() { + return it('should parse an empty query params when going from -> to, when no querystring in the url', function(done) { + var app, createPage, history, onRoute, options, routes; + this.timeout(2000); + app = {}; + createPage = function(req, res) { + return { + model: {} + }; + }; + onRoute = function(callback, page, params, next, isTransitional, done) { + if (isTransitional) { + if (callback.length === 4) { + callback(page.model, params, next, done); + return true; + } else { + callback(page.model, params, next); + return; + } + } + return callback(page, page.model, params, next); + }; + routes = tracks.setup(app, createPage, onRoute); + app.get({ + from: '/a/b', + to: '/x/y' + }, function(model, params, next) { + expect(params.query).to.eql({}); + return done(); + }); + history = app.history; + options = { + method: 'get', + url: '/x/y', + previous: '/a/b', + body: '' + }; + return router.render(history.page(), options); + }); +});