Skip to content

Commit cab241b

Browse files
committed
test(query-devtools/utils): add tests for 'convertRemToPixels'
1 parent 8a5d189 commit cab241b

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

packages/query-devtools/src/__tests__/utils.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
22
import {
3+
convertRemToPixels,
34
deleteNestedDataByPath,
45
displayValue,
56
getMutationStatusColor,
@@ -846,4 +847,35 @@ describe('Utils tests', () => {
846847
expect(getSidedProp('padding', 'right')).toBe('paddingRight')
847848
})
848849
})
850+
851+
describe('convertRemToPixels', () => {
852+
beforeEach(() => {
853+
document.documentElement.style.fontSize = '16px'
854+
})
855+
856+
afterEach(() => {
857+
document.documentElement.style.fontSize = ''
858+
})
859+
860+
it('should convert 1 rem to the document root font size in pixels', () => {
861+
expect(convertRemToPixels(1)).toBe(16)
862+
})
863+
864+
it('should return 0 for 0 rem', () => {
865+
expect(convertRemToPixels(0)).toBe(0)
866+
})
867+
868+
it('should multiply rem by the document root font size', () => {
869+
expect(convertRemToPixels(2)).toBe(32)
870+
})
871+
872+
it('should support decimal rem values', () => {
873+
expect(convertRemToPixels(0.5)).toBe(8)
874+
})
875+
876+
it('should reflect the current document root font size', () => {
877+
document.documentElement.style.fontSize = '20px'
878+
expect(convertRemToPixels(1)).toBe(20)
879+
})
880+
})
849881
})

0 commit comments

Comments
 (0)