Skip to content

Commit 23a3524

Browse files
test: css supports
1 parent 3bd84b2 commit 23a3524

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/test/utils.spec.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { debounce, computeTooltipPosition, cssTimeToMs } from 'utils'
1+
import { debounce, computeTooltipPosition, cssTimeToMs, cssSupports } from 'utils'
22

33
// Tell Jest to mock all timeout functions
44
jest.useRealTimers()
@@ -134,6 +134,35 @@ describe('debounce', () => {
134134
})
135135
})
136136

137+
describe('css supports', () => {
138+
let windowSpy
139+
140+
beforeEach(() => {
141+
windowSpy = jest.spyOn(window, 'window', 'get')
142+
})
143+
144+
afterEach(() => {
145+
windowSpy.mockRestore()
146+
})
147+
148+
test('returns true if css property is supported', () => {
149+
expect(cssSupports('position', 'relative')).toBe(true)
150+
})
151+
152+
test('returns false if css property is not supported', () => {
153+
expect(cssSupports('position', 'foo')).toBe(false)
154+
})
155+
156+
test('returns true if `window.CSS.supports` is not available', () => {
157+
windowSpy.mockImplementation(() => ({
158+
CSS: {
159+
supports: undefined,
160+
},
161+
}))
162+
expect(cssSupports('position', 'foo')).toBe(true)
163+
})
164+
})
165+
137166
describe('css time to ms', () => {
138167
test('converts time correctly', () => {
139168
expect(cssTimeToMs('1s')).toBe(1000)

0 commit comments

Comments
 (0)