|
| 1 | +var expect = require('expect'); |
| 2 | +var React = require('react'); |
| 3 | +var { Foo, RedirectToFoo } = require('../../__tests__/TestHandlers'); |
| 4 | +var TestLocation = require('../../locations/TestLocation'); |
| 5 | +var Route = require('../../components/Route'); |
| 6 | +var Router = require('../../index'); |
| 7 | +var History = require('../History'); |
| 8 | + |
| 9 | +describe('History', function () { |
| 10 | + describe('on the initial page load', function () { |
| 11 | + it('has length 1', function () { |
| 12 | + expect(History.length).toEqual(1); |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + describe('after navigating to a route', function () { |
| 17 | + beforeEach(function () { |
| 18 | + TestLocation.history = [ '/foo' ]; |
| 19 | + }); |
| 20 | + |
| 21 | + it('has length 2', function (done) { |
| 22 | + var routes = [ |
| 23 | + <Route name="foo" handler={Foo}/>, |
| 24 | + <Route name="about" handler={Foo}/> |
| 25 | + ]; |
| 26 | + |
| 27 | + var count = 0; |
| 28 | + |
| 29 | + var router = Router.run(routes, TestLocation, function (Handler) { |
| 30 | + count += 1; |
| 31 | + |
| 32 | + if (count === 2) { |
| 33 | + expect(History.length).toEqual(2); |
| 34 | + done(); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + router.transitionTo('about'); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('that redirects to another route', function () { |
| 42 | + it('has length 2', function (done) { |
| 43 | + var routes = [ |
| 44 | + <Route name="foo" handler={Foo}/>, |
| 45 | + <Route name="about" handler={RedirectToFoo}/> |
| 46 | + ]; |
| 47 | + |
| 48 | + var count = 0; |
| 49 | + |
| 50 | + var router = Router.run(routes, TestLocation, function (Handler) { |
| 51 | + count += 1; |
| 52 | + |
| 53 | + if (count === 2) { |
| 54 | + expect(History.length).toEqual(2); |
| 55 | + done(); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
| 59 | + router.transitionTo('about'); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments