File tree Expand file tree Collapse file tree 3 files changed +256
-44
lines changed
package/deviceUtil/getDevice Expand file tree Collapse file tree 3 files changed +256
-44
lines changed Original file line number Diff line number Diff line change @@ -23,30 +23,6 @@ describe("getDevice", () => {
2323 mockUserAgent ( "" ) ;
2424 } ) ;
2525
26- // * ----- 1. SSR 환경 테스트 ----- * //
27- describe ( "SSR (Server-Side Rendering) 환경" , ( ) => {
28- test ( "window 객체가 없을 때, 기본 데스크톱 정보를 반환해야 합니다" , ( ) => {
29- // 'window' 객체를 일시적으로 없애서 SSR 환경을 시뮬레이션합니다.
30- const originalWindow = global . window ;
31- // @ts -ignore: 'window' is a read-only property.
32- delete global . window ;
33-
34- const device = getDevice ( ) ;
35-
36- expect ( device ) . toEqual ( {
37- isMobile : false ,
38- isTablet : false ,
39- isDesktop : true ,
40- isIOS : false ,
41- isAndroid : false ,
42- } ) ;
43-
44- // 다른 테스트에 영향을 주지 않도록 window 객체를 복원합니다.
45- global . window = originalWindow ;
46- } ) ;
47- } ) ;
48-
49- // * ----- 2. 클라이언트 환경 테스트 ----- * //
5026 describe ( "클라이언트 (브라우저) 환경" , ( ) => {
5127 describe ( "데스크톱" , ( ) => {
5228 test ( "Windows Chrome User Agent를 데스크톱으로 인식해야 합니다" , ( ) => {
Original file line number Diff line number Diff line change 1010/**
1111 * 사용자의 디바이스 환경 정보를 반환합니다.
1212 * window.navigator.userAgent를 기반으로 분석하며, 클라이언트 사이드에서만 정확한 값을 반환합니다.
13- * 서버 사이드 렌더링(SSR) 환경에서는 에러를 방지하기 위해 기본값으로 데스크톱 환경 정보를 반환합니다.
1413 *
1514 * @returns {DeviceInfo } 디바이스 환경 정보 객체
1615 */
1716export default function getDevice ( ) {
18- // * ----- SSR 환경일 경우, 기본값(데스크톱)을 반환하여 에러 방지 ----- * //
19- if ( typeof window === "undefined" || ! window . navigator ) {
20- return {
21- isMobile : false ,
22- isTablet : false ,
23- isDesktop : true ,
24- isIOS : false ,
25- isAndroid : false ,
26- } ;
27- }
28-
2917 // * ----- 클라이언트 환경일 경우, 실행 ----- * //
3018 const userAgent = window . navigator . userAgent ;
3119
You can’t perform that action at this time.
0 commit comments