forked from fingerprintjs/fingerprintjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevice_memory.test.ts
36 lines (32 loc) · 1.31 KB
/
device_memory.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { withMockProperties } from '../../tests/utils'
import getDeviceMemory from './device_memory'
describe('Sources', () => {
describe('deviceMemory', () => {
it('returns number or undefined for the current browser', () => {
const deviceMemory = getDeviceMemory()
expect(['number', 'undefined'].indexOf(typeof deviceMemory)).not.toBe(-1)
if (typeof deviceMemory === 'number') {
expect(deviceMemory).not.toBeNaN()
expect(deviceMemory).toBeGreaterThan(0)
}
})
it('handles numeric values', async () => {
// Configuring the mock property as `{ value: 8 }` doesn't work in old browsers.
await withMockProperties(navigator, { deviceMemory: { get: () => 8 } }, () => {
expect(getDeviceMemory()).toBe(8)
})
})
it('handles undefined values', async () => {
await withMockProperties(navigator, { deviceMemory: { get: () => undefined } }, () => {
expect(getDeviceMemory()).toBeUndefined()
})
})
// Some browsers return a string value for `deviceMemory`.
// This test checks that it's fetched as a number regardless.
it('converts fake string value to number', async () => {
await withMockProperties(navigator, { deviceMemory: { get: () => '4' } }, () => {
expect(getDeviceMemory()).toBe(4)
})
})
})
})