Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error when component is undefined or null (#2038) #2041

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
@@ -47,7 +47,8 @@ function addRouteRecord (
nameMap: Dictionary<RouteRecord>,
route: RouteConfig,
parent?: RouteRecord,
matchAs?: string
matchAs?: string,
isAnAlias?: boolean
) {
const { path, name } = route
if (process.env.NODE_ENV !== 'production') {
@@ -57,6 +58,12 @@ function addRouteRecord (
`route config "component" for path: ${String(path || name)} cannot be a ` +
`string id. Use an actual component instead.`
)
warn(
route.component || route.components || route.redirect || route.beforeEnter || isAnAlias,
`route config "component" for path: ${String(path || name)} should be either a ` +
`component (or named component), redirection, navigation guard, or an alias ` +
`to another root.`
)
}

const pathToRegexpOptions: PathToRegexpOptions = route.pathToRegexpOptions || {}
@@ -128,7 +135,8 @@ function addRouteRecord (
nameMap,
aliasRoute,
parent,
record.path || '/' // matchAs
record.path || '/', // matchAs
true
)
})
}
6 changes: 6 additions & 0 deletions test/unit/specs/create-map.spec.js
Original file line number Diff line number Diff line change
@@ -78,6 +78,12 @@ describe('Creating Route Map', function () {
}).toThrowError(/"path" is required/)
})

it('in development, throws if component is null or undefined', function () {
process.env.NODE_ENV = 'development'
maps = createRouteMap([{ path: '/' }])
expect(console.warn).toHaveBeenCalled()
})

Copy link

@vinibrsl vinibrsl Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create an spec similar to this one, but to test that this is not affecting production env, with not.toHaveBeenCalled 👍

it('in production, it has not logged this warning', function () {
maps = createRouteMap(routes)
expect(console.warn).not.toHaveBeenCalled()