-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added new
parseQueryString
method.
- Loading branch information
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* tslint:disable:no-expression-statement no-object-mutation */ | ||
|
||
import { factoryParameters } from '../lib/store' | ||
import { pm } from '../lib/utils' | ||
import { serializers } from '../lib/serializers' | ||
|
||
describe('static parseQueryString', () => { | ||
const initialValues = { someParameter: 'test' } | ||
const { parseQueryString } = factoryParameters( | ||
{ | ||
someParameter: pm('wow', serializers.string), | ||
}, | ||
initialValues | ||
) | ||
|
||
it('should parse a query string', () => { | ||
const result = parseQueryString('?wow=nice') | ||
expect(result).toEqual({ someParameter: 'nice' }) | ||
}) | ||
|
||
it('should return defaults if empty', () => { | ||
const result = parseQueryString('') | ||
expect(result).toEqual(initialValues) | ||
}) | ||
it('should return defaults if different string', () => { | ||
const result = parseQueryString('?somethingElse=cool') | ||
expect(result).toEqual(initialValues) | ||
}) | ||
it('should allow to override defaults', () => { | ||
const newDefaults = { someParameter: 'otherDefault' } | ||
const result = parseQueryString('', newDefaults) | ||
expect(result).toEqual(newDefaults) | ||
}) | ||
}) |
This file contains 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