From 23a3524e97ef4aa852394958b8f3f25b8fcaf2ff Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Sat, 10 Feb 2024 15:07:36 -0300 Subject: [PATCH] test: css supports --- src/test/utils.spec.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/test/utils.spec.js b/src/test/utils.spec.js index 3bd3cef5..c7102dcd 100644 --- a/src/test/utils.spec.js +++ b/src/test/utils.spec.js @@ -1,4 +1,4 @@ -import { debounce, computeTooltipPosition, cssTimeToMs } from 'utils' +import { debounce, computeTooltipPosition, cssTimeToMs, cssSupports } from 'utils' // Tell Jest to mock all timeout functions jest.useRealTimers() @@ -134,6 +134,35 @@ describe('debounce', () => { }) }) +describe('css supports', () => { + let windowSpy + + beforeEach(() => { + windowSpy = jest.spyOn(window, 'window', 'get') + }) + + afterEach(() => { + windowSpy.mockRestore() + }) + + test('returns true if css property is supported', () => { + expect(cssSupports('position', 'relative')).toBe(true) + }) + + test('returns false if css property is not supported', () => { + expect(cssSupports('position', 'foo')).toBe(false) + }) + + test('returns true if `window.CSS.supports` is not available', () => { + windowSpy.mockImplementation(() => ({ + CSS: { + supports: undefined, + }, + })) + expect(cssSupports('position', 'foo')).toBe(true) + }) +}) + describe('css time to ms', () => { test('converts time correctly', () => { expect(cssTimeToMs('1s')).toBe(1000)