From 70a42723283e89b795dd351dd14cd61a6032840f Mon Sep 17 00:00:00 2001 From: Jinwoo Oh Date: Wed, 2 Nov 2016 00:58:50 +0900 Subject: [PATCH] fix: Pass transition hook's arguments correctly (#4123) --- modules/TransitionUtils.js | 8 ++++---- modules/__tests__/transitionHooks-test.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/TransitionUtils.js b/modules/TransitionUtils.js index 807e316544..a1382a8b5e 100644 --- a/modules/TransitionUtils.js +++ b/modules/TransitionUtils.js @@ -82,9 +82,9 @@ export function runEnterHooks(routes, nextState, callback) { enterHooks.clear() const hooks = getEnterHooks(routes) return runTransitionHooks(hooks.length, (index, replace, next) => { - const wrappedNext = () => { + const wrappedNext = (...args) => { if (enterHooks.has(hooks[index])) { - next() + next(...args) enterHooks.remove(hooks[index]) } } @@ -106,9 +106,9 @@ export function runChangeHooks(routes, state, nextState, callback) { changeHooks.clear() const hooks = getChangeHooks(routes) return runTransitionHooks(hooks.length, (index, replace, next) => { - const wrappedNext = () => { + const wrappedNext = (...args) => { if (changeHooks.has(hooks[index])) { - next() + next(...args) changeHooks.remove(hooks[index]) } } diff --git a/modules/__tests__/transitionHooks-test.js b/modules/__tests__/transitionHooks-test.js index e77575d9b5..1e36265b49 100644 --- a/modules/__tests__/transitionHooks-test.js +++ b/modules/__tests__/transitionHooks-test.js @@ -6,6 +6,7 @@ import { routerShape } from '../PropTypes' import execSteps from './execSteps' import Router from '../Router' import Route from '../Route' +import match from '../match' describe('When a router enters a branch', function () { let @@ -397,13 +398,17 @@ describe('Changing location', () => { cb() }) } + const onEnterError = (state, replace, cb) => { + cb(new Error('transition error')) + } const createRoutes = ({ enter, change }) => [ , , - + , + ] beforeEach(() => { @@ -443,4 +448,16 @@ describe('Changing location', () => { }) }) }) + + it('should pass error correctly', (done) => { + const routes = createRoutes({ enter: true }) + + match({ routes, location: '/error' }, (error, redirectLocation, renderProps) => { + expect(error).toExist() + expect(error.message).toEqual('transition error') + expect(redirectLocation).toNotExist() + expect(renderProps).toNotExist() + done() + }) + }) })