Skip to content

Commit e4a5335

Browse files
eunwoo-leviclaudekimyouknow
authored
test(mobile): add missing SSR environment tests (#346)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: 김윤호 yunho <kimyouknow@naver.com>
1 parent 4b0c59e commit e4a5335

7 files changed

Lines changed: 133 additions & 0 deletions

File tree

.pnp.cjs

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mobile/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@testing-library/react": "^16.1.0",
6262
"@types/react": "^19.0.0",
6363
"@types/react-dom": "^19.0.0",
64+
"@vitest/coverage-v8": "^2.1.8",
6465
"eslint": "^9.16.0",
6566
"react": "^19.0.0",
6667
"react-dom": "^19.0.0",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @vitest-environment node
3+
*
4+
* SSR environment tests - runs in Node.js where window is truly undefined
5+
*/
6+
import { describe, expect, it } from 'vitest';
7+
8+
import { useKeyboardHeight } from './useKeyboardHeight.ts';
9+
10+
describe('useKeyboardHeight SSR environment', () => {
11+
it('should be safe on server side rendering', () => {
12+
expect(typeof window).toBe('undefined');
13+
14+
// Should not throw during module evaluation
15+
expect(() => useKeyboardHeight).not.toThrow();
16+
});
17+
18+
it('should not throw when imported in SSR', () => {
19+
// In Node environment, window is undefined
20+
expect(typeof window).toBe('undefined');
21+
22+
// Just verify the hook can be called (doesn't actually run without React context)
23+
expect(typeof useKeyboardHeight).toBe('function');
24+
});
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @vitest-environment node
3+
*
4+
* SSR environment tests - runs in Node.js where window is truly undefined
5+
*/
6+
import { describe, expect, it } from 'vitest';
7+
8+
import { useAvoidKeyboard } from './useAvoidKeyboard.ts';
9+
10+
describe('useAvoidKeyboard SSR environment', () => {
11+
it('should be safe on server side rendering', () => {
12+
expect(typeof window).toBe('undefined');
13+
14+
// Should not throw during module evaluation
15+
expect(() => useAvoidKeyboard).not.toThrow();
16+
});
17+
18+
it('should not throw when imported in SSR', () => {
19+
// In Node environment, window is undefined
20+
expect(typeof window).toBe('undefined');
21+
22+
// Just verify the hook can be called (doesn't actually run without React context)
23+
expect(typeof useAvoidKeyboard).toBe('function');
24+
});
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @vitest-environment node
3+
*
4+
* SSR environment tests - runs in Node.js where window is truly undefined
5+
*/
6+
import { describe, expect, it } from 'vitest';
7+
8+
import { useNetworkStatus } from './useNetworkStatus.ts';
9+
10+
describe('useNetworkStatus SSR environment', () => {
11+
it('should be safe on server side rendering', () => {
12+
expect(typeof window).toBe('undefined');
13+
14+
// Should not throw during module evaluation
15+
expect(() => useNetworkStatus).not.toThrow();
16+
});
17+
18+
it('should not throw when imported in SSR', () => {
19+
// In Node environment, window is undefined
20+
expect(typeof window).toBe('undefined');
21+
22+
// Just verify the hook can be called (doesn't actually run without React context)
23+
expect(typeof useNetworkStatus).toBe('function');
24+
});
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @vitest-environment node
3+
*
4+
* SSR environment tests - runs in Node.js where window is truly undefined
5+
*/
6+
import { describe, expect, it } from 'vitest';
7+
8+
import { usePageVisibility } from './usePageVisibility.ts';
9+
10+
describe('usePageVisibility SSR environment', () => {
11+
it('should be safe on server side rendering', () => {
12+
expect(typeof window).toBe('undefined');
13+
14+
// Should not throw during module evaluation
15+
expect(() => usePageVisibility).not.toThrow();
16+
});
17+
18+
it('should not throw when imported in SSR', () => {
19+
// In Node environment, window is undefined
20+
expect(typeof window).toBe('undefined');
21+
22+
// Just verify the hook can be called (doesn't actually run without React context)
23+
expect(typeof usePageVisibility).toBe('function');
24+
});
25+
});

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,6 +3685,7 @@ __metadata:
36853685
"@testing-library/react": "npm:^16.1.0"
36863686
"@types/react": "npm:^19.0.0"
36873687
"@types/react-dom": "npm:^19.0.0"
3688+
"@vitest/coverage-v8": "npm:^2.1.8"
36883689
eslint: "npm:^9.16.0"
36893690
react: "npm:^19.0.0"
36903691
react-dom: "npm:^19.0.0"

0 commit comments

Comments
 (0)