2017-03-17 13:09:42 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-03-17 13:09:42 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2019-07-16 17:58:47 -04:00
|
|
|
import {convertToParamMap, ParamMap, Params} from '../src/shared';
|
2017-03-17 13:09:42 -04:00
|
|
|
|
|
|
|
describe('ParamsMap', () => {
|
|
|
|
it('should returns whether a parameter is present', () => {
|
|
|
|
const map = convertToParamMap({single: 's', multiple: ['m1', 'm2']});
|
|
|
|
expect(map.has('single')).toEqual(true);
|
|
|
|
expect(map.has('multiple')).toEqual(true);
|
|
|
|
expect(map.has('not here')).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2017-03-20 12:19:25 -04:00
|
|
|
it('should returns the name of the parameters', () => {
|
|
|
|
const map = convertToParamMap({single: 's', multiple: ['m1', 'm2']});
|
|
|
|
expect(map.keys).toEqual(['single', 'multiple']);
|
|
|
|
});
|
|
|
|
|
2017-03-17 13:09:42 -04:00
|
|
|
it('should support single valued parameters', () => {
|
|
|
|
const map = convertToParamMap({single: 's', multiple: ['m1', 'm2']});
|
|
|
|
expect(map.get('single')).toEqual('s');
|
|
|
|
expect(map.get('multiple')).toEqual('m1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support multiple valued parameters', () => {
|
|
|
|
const map = convertToParamMap({single: 's', multiple: ['m1', 'm2']});
|
|
|
|
expect(map.getAll('single')).toEqual(['s']);
|
|
|
|
expect(map.getAll('multiple')).toEqual(['m1', 'm2']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return `null` when a single valued element is absent', () => {
|
|
|
|
const map = convertToParamMap({});
|
|
|
|
expect(map.get('name')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
2018-03-10 12:14:58 -05:00
|
|
|
it('should return `[]` when a multiple valued element is absent', () => {
|
2017-03-17 13:09:42 -04:00
|
|
|
const map = convertToParamMap({});
|
|
|
|
expect(map.getAll('name')).toEqual([]);
|
|
|
|
});
|
2019-07-16 17:58:47 -04:00
|
|
|
|
|
|
|
it('should not error when trying to call ParamMap.get function using an object created with Object.create() function',
|
|
|
|
() => {
|
|
|
|
const objectToMap: Params = Object.create(null);
|
|
|
|
objectToMap['single'] = 's';
|
|
|
|
objectToMap['multiple'] = ['m1', 'm2'];
|
|
|
|
const paramMaps: ParamMap = convertToParamMap(objectToMap);
|
|
|
|
expect(() => paramMaps.get('single')).not.toThrow();
|
|
|
|
expect(paramMaps.get('single')).toEqual('s');
|
|
|
|
});
|
2020-05-19 15:08:49 -04:00
|
|
|
});
|