fix(router): freeze params and queryParams to prevent common source of bugs

This commit is contained in:
vsavkin
2016-07-14 13:33:05 -07:00
parent 44ff005ce3
commit 0668ba50e8
2 changed files with 18 additions and 4 deletions

View File

@ -12,6 +12,14 @@ describe('recognize', () => {
});
});
it('should freeze params object', () => {
checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent);
const child = s.firstChild(s.root);
expect(() => child.params['prop'] = "new").toThrowError(/Can't add property/);
});
});
it('should support secondary routes', () => {
checkRecognize(
[
@ -504,6 +512,12 @@ describe('recognize', () => {
expect(s.queryParams).toEqual({q: '11'});
});
});
it('should freeze query params object', () => {
checkRecognize([{path: 'a', component: ComponentA}], 'a?q=11', (s: RouterStateSnapshot) => {
expect(() => s.queryParams['prop'] = "new").toThrowError(/Can't add property/);
});
});
});
describe('fragment', () => {