Skip to content

Commit

Permalink
test: css supports
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed Feb 18, 2024
1 parent 3bd84b2 commit 23a3524
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 23a3524

Please sign in to comment.