-
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.
Merge pull request #10 from oaoong/NABI-384
🧪 object 관련 함수 테스트
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 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,39 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { getQueryParams } from './getQueryParams' | ||
|
||
describe('getQueryParams 함수 테스트', () => { | ||
it('일반적인 경우: 객체를 쿼리 파라미터 문자열로 변환', () => { | ||
const params = { name: 'Alice', age: '30' } | ||
const result = getQueryParams(params) | ||
expect(result).toBe('name=Alice&age=30') | ||
}) | ||
|
||
it('빈 객체: 빈 객체를 전달했을 때 빈 문자열 반환', () => { | ||
const params = {} | ||
const result = getQueryParams(params) | ||
expect(result).toBe('') | ||
}) | ||
|
||
it('null 또는 undefined 값 포함: null 또는 undefined 값을 무시하고 문자열 변환', () => { | ||
const params = { | ||
name: 'Alice', | ||
age: null, | ||
gender: undefined, | ||
city: 'New York', | ||
} | ||
const result = getQueryParams(params) | ||
expect(result).toBe('name=Alice&city=New+York') | ||
}) | ||
|
||
it('특수 문자 처리: 특수 문자를 올바르게 인코딩', () => { | ||
const params = { | ||
'user name': 'Alice & Bob', | ||
city: 'New York', | ||
details: 'age=30&height=170', | ||
} | ||
const result = getQueryParams(params) | ||
expect(result).toBe( | ||
'user+name=Alice+%26+Bob&city=New+York&details=age%3D30%26height%3D170', | ||
) | ||
}) | ||
}) |
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 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { getValueByKey } from './getValueByKey' | ||
|
||
describe('getValueByKey 함수 테스트', () => { | ||
it('정상적인 경우: 일치하는 키가 있는 경우 해당 값 반환', () => { | ||
const array = [ | ||
{ key: 'name', value: 'Alice' }, | ||
{ key: 'age', value: '30' }, | ||
] | ||
const result = getValueByKey(array, 'name') | ||
expect(result).toBe('Alice') | ||
}) | ||
|
||
it('키가 없는 경우: 일치하는 키가 없을 때 undefined 반환', () => { | ||
const array = [ | ||
{ key: 'name', value: 'Alice' }, | ||
{ key: 'age', value: '30' }, | ||
] | ||
const result = getValueByKey(array, 'gender') | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
it('빈 배열: 빈 배열을 전달했을 때 undefined 반환', () => { | ||
const array = [] as any | ||
const result = getValueByKey(array, 'name') | ||
expect(result).toBeUndefined() | ||
}) | ||
|
||
it('잘못된 형식의 입력: 객체 배열 대신 다른 형식의 입력 처리', () => { | ||
const invalidInput = 'This is not an array' | ||
const result = () => getValueByKey(invalidInput, 'name') | ||
expect(result).toThrow(TypeError) | ||
}) | ||
}) |