expect(result).toEqual(resolved)
}
+ /**
+ *
+ * @param {import('../src/types').RouteRecord} record
+ * @param {import('../src/types').MatcherLocation} location
+ * @param {import('../src/types').MatcherLocationNormalized} start
+ * @returns {any} error
+ */
+ function assertErrorMatch(
+ record,
+ location,
+ start = START_LOCATION_NORMALIZED
+ ) {
+ try {
+ assertRecordMatch(record, location, {}, start)
+ } catch (error) {
+ return error
+ }
+ }
+
describe('LocationAsPath', () => {
it('resolves a normal path', () => {
assertRecordMatch(
{ name: undefined, params: { id: 'posva', other: 'hey' } }
)
})
+
+ it('throws if the path does not exists', () => {
+ expect(
+ assertErrorMatch({ path: '/', component }, { path: '/foo' })
+ ).toMatchInlineSnapshot(
+ `[Error: No match for {"path":"/foo","params":{},"query":{},"hash":"","fullPath":"/"}]`
+ )
+ })
})
describe('LocationAsName', () => {
{ name: 'UserEdit', path: '/users/posva/m/admin' }
)
})
+
+ it('throws if the named route does not exists', () => {
+ expect(
+ assertErrorMatch({ path: '/', component }, { name: 'Home' })
+ ).toMatchInlineSnapshot(
+ `[Error: No match for {"path":"/","name":"Home","params":{},"query":{},"hash":"","fullPath":"/"}]`
+ )
+ })
})
describe('LocationAsRelative', () => {
}
)
})
+
+ it('throws if the current named route does not exists', () => {
+ expect(
+ assertErrorMatch(
+ { path: '/', component },
+ {},
+ { name: 'home', params: {}, path: '/' }
+ )
+ ).toMatchInlineSnapshot(
+ `[Error: No match for {"name":"home","params":{},"path":"/"}]`
+ )
+ })
})
})
})
export class NoRouteMatchError extends Error {
constructor(currentLocation: any, location: any) {
- super('No match for' + JSON.stringify({ ...currentLocation, ...location }))
+ super('No match for ' + JSON.stringify({ ...currentLocation, ...location }))
Object.setPrototypeOf(this, new.target.prototype)
}
}