Skip to content

Instantly share code, notes, and snippets.

@lexfrl
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save lexfrl/f9d1a8a15e6f6c3e0af0 to your computer and use it in GitHub Desktop.

Select an option

Save lexfrl/f9d1a8a15e6f6c3e0af0 to your computer and use it in GitHub Desktop.
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