Skip to content

Commit 24a0724

Browse files
committed
Add failing test
1 parent 39a13c6 commit 24a0724

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/js/route.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,26 @@ describe('route()', () => {
791791
expect(route('catalog-domain-param-path', ['/p/test'], false)).toBe('/catalog//p/test');
792792
});
793793

794+
// Highest potential for "breaking" changes when fixing these is the second format in each example, where
795+
// params are passed as an array, because it's less clear in that case which param is which since we're
796+
// relying on the order they're passed. It may break some people's code but it's probably more
797+
// important to match Laravel's behaviour correctly, this is a pretty big inconsistency.
798+
test('handle domain parameters when generating relative URL', () => {
799+
// Just for demonstration purposes, this is tested properly elsewhere
800+
expect(route('team.user.show', { team: 1, id: 2 })).toBe('https://1.ziggy.dev/users/2');
801+
expect(route('team.user.show', [1, 2])).toBe('https://1.ziggy.dev/users/2');
802+
803+
// Laravel route() errors here, domain {team} param is required
804+
// We should *probably* match that behaviour and error too
805+
expect(route('team.user.show', { id: 2 }, false)).toBe('/users/2');
806+
expect(route('team.user.show', [2], false)).toBe('/users/2');
807+
808+
// Laravel route() handles these find, {team} param is recognized even though final output won't contain it
809+
// We should *definitely* match that behaviour and handle these properly
810+
expect(route('team.user.show', { team: 1, id: 2 }, false)).toBe('/users/2');
811+
expect(route('team.user.show', [1, 2], false)).toBe('/users/2');
812+
});
813+
794814
test('skip encoding some characters in route parameters', () => {
795815
// Laravel doesn't encode these characters in route parameters: / @ : ; , = + ! * | ? & # %
796816
expect(route('pages', 'a/b')).toBe('https://ziggy.dev/a/b');

0 commit comments

Comments
 (0)