Last active
August 29, 2015 14:22
-
-
Save lexfrl/f9d1a8a15e6f6c3e0af0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Router from "../router"; | |
| describe('Router', () => { | |
| const router = new Router(require('./data/routes')); | |
| it('should match correct route name', () => { | |
| expect(router.match('http://example.com/users/1/comments').name).toBe('users.comments'); | |
| expect(router.match('http://example.com/users').name).toBe('users'); | |
| }); | |
| it('should match correct route name even with slashes', () => { | |
| expect(router.match('http://example.com/users/1/comments/').name).toBe('users.comments'); | |
| expect(router.match('http://example.com/users/').name).toBe('users'); | |
| }); | |
| it('should match route params', () => { | |
| expect(router.match('http://example.com/users/1/comments').params).toEqual({id: '1'}); | |
| expect(router.match('http://example.com/users/1').params).toEqual({id: '1'}); | |
| }); | |
| it('should match query params', () => { | |
| expect(router.match('http://example.com/users?id=1').params).toEqual({id: '1'}); | |
| }); | |
| it('should prefer route params over query params', () => { | |
| expect(router.match('http://example.com/users/1?id=2').params).toEqual({id: '1'}); | |
| }); | |
| it('should return original query param even if there is a route param with the same name', () => { | |
| expect(router.match('http://example.com/users/1?id=2').query).toEqual({id: '2'}); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment