Skip to content

Commit e3d6a06

Browse files
committed
device: add test
1 parent 1b008a8 commit e3d6a06

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

client/utils/device.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { isMac } from './device';
2+
3+
describe('isMac', () => {
4+
const originalUserAgent = navigator.userAgent;
5+
6+
afterEach(() => {
7+
// Restore the original userAgent after each test
8+
Object.defineProperty(navigator, 'userAgent', {
9+
value: originalUserAgent,
10+
configurable: true
11+
});
12+
});
13+
14+
it('returns true when userAgent contains "Mac"', () => {
15+
Object.defineProperty(navigator, 'userAgent', {
16+
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
17+
configurable: true
18+
});
19+
expect(isMac()).toBe(true);
20+
});
21+
22+
it('returns false when userAgent does not contain "Mac"', () => {
23+
Object.defineProperty(navigator, 'userAgent', {
24+
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
25+
configurable: true
26+
});
27+
expect(isMac()).toBe(false);
28+
});
29+
});

0 commit comments

Comments
 (0)