-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Fix: path param 가져오는 함수 이름 변경 및 테스트 코드 추가
- Loading branch information
Showing
3 changed files
with
27 additions
and
9 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
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
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,17 +1,35 @@ | ||
import { addRoute, routerRegistry } from "../../src/utils/router"; | ||
import { | ||
addRoute, | ||
getPathParamsFromRoute, | ||
routerRegistry, | ||
} from "../../src/utils/router"; | ||
|
||
describe("addRoute 테스트", () => { | ||
test("path가 pathParam을 포함하지 않는 경우", () => { | ||
addRoute("/test", () => {}); | ||
expect(RegExp(routerRegistry[0].testRegExp).exec("/test")).toBeTruthy(); | ||
expect(RegExp(routerRegistry[0].testRegExp).exec("/text")).toBeFalsy(); | ||
routerRegistry.pop(); | ||
}); | ||
|
||
test("path가 pathParam을 포함하는 경우", () => { | ||
addRoute("/test/:data", () => {}); | ||
expect( | ||
RegExp(routerRegistry[1].testRegExp).exec("/test/testData") | ||
RegExp(routerRegistry[0].testRegExp).exec("/test/testData") | ||
).toBeTruthy(); | ||
expect(RegExp(routerRegistry[1].testRegExp).exec("/test")).toBeFalsy(); | ||
expect(RegExp(routerRegistry[0].testRegExp).exec("/test")).toBeFalsy(); | ||
routerRegistry.pop(); | ||
}); | ||
}); | ||
|
||
describe("getPathParamsFromRoute 테스트", () => { | ||
test("route에 저장된 정규표현식과 일치하는 데이터 리턴", () => { | ||
addRoute("/test/:data", () => {}); | ||
const route = routerRegistry[0]; | ||
const param = getPathParamsFromRoute(route, "/test/123"); | ||
expect(param).toEqual({ | ||
data: "123", | ||
}); | ||
routerRegistry.pop(); | ||
}); | ||
}); |