-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
15 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 |
---|---|---|
@@ -1,23 +1,51 @@ | ||
import { getQueryFromUrl } from './get-query-string' | ||
|
||
describe('getQueryStringFromUrl()', () => { | ||
it('should work for urls without trailing slash', () => { | ||
const testString = 'https://test.com?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
describe('getQueryStringFromUrl() ', () => { | ||
describe('positive', () => { | ||
it('should retrieve query parameters', () => { | ||
const testString = 'https://test.com?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
expect(getQueryFromUrl(testString)).toBeInstanceOf(URLSearchParams) | ||
expect(getQueryFromUrl(testString)?.get('hello')).toBe('2') | ||
}) | ||
it('should retrieve query parameters', () => { | ||
const testString = '/?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
expect(getQueryFromUrl(testString)).toBeInstanceOf(URLSearchParams) | ||
expect(getQueryFromUrl(testString)?.get('hello')).toBe('2') | ||
}) | ||
it('should retrieve query parameters', () => { | ||
const testString = '?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
expect(getQueryFromUrl(testString)).toBeInstanceOf(URLSearchParams) | ||
expect(getQueryFromUrl(testString)?.get('hello')).toBe('2') | ||
}) | ||
it('should retrieve query parameters', () => { | ||
const testString = 'https://test.com/hello/?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
expect(getQueryFromUrl(testString)).toBeInstanceOf(URLSearchParams) | ||
expect(getQueryFromUrl(testString)?.get('hello')).toBe('2') | ||
}) | ||
}) | ||
|
||
it('should work for urls without trailing slash', () => { | ||
const testString = '/?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
}) | ||
describe('negative', () => { | ||
it('should not find any query parameters', () => { | ||
const testString = 'https://test.com' | ||
expect(getQueryFromUrl(testString)).toBeUndefined() | ||
}) | ||
it('should not find any query parameters', () => { | ||
const testString = '/hello' | ||
expect(getQueryFromUrl(testString)).toBeUndefined() | ||
}) | ||
|
||
it('should work for urls without trailing slash', () => { | ||
const testString = '?hello=2' | ||
expect(getQueryFromUrl(testString)).not.toBeUndefined() | ||
}) | ||
it('should not find any query parameters', () => { | ||
const testString = '' | ||
expect(getQueryFromUrl(testString)).toBeUndefined() | ||
}) | ||
|
||
it('should work for urls without trailing slash', () => { | ||
const testString = 'https://test.com' | ||
expect(getQueryFromUrl(testString)).toBeUndefined() | ||
it('should not find any query parameters', () => { | ||
const testString = 'https://test.com/hello' | ||
expect(getQueryFromUrl(testString)).toBeUndefined() | ||
}) | ||
}) | ||
}) |