Skip to content

Commit

Permalink
feat: better test cases
Browse files Browse the repository at this point in the history
BibiSebi committed Jul 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 6b69641 commit d8de8c5
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions src/utils/query-params/get-query-string.test.ts
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()
})
})
})

0 comments on commit d8de8c5

Please sign in to comment.