|
| 1 | +import { useCssSupports } from '@vueuse/core' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { shallowRef } from 'vue' |
| 4 | + |
| 5 | +describe('useCssSupports', () => { |
| 6 | + it('should be defined', () => { |
| 7 | + expect(useCssSupports).toBeDefined() |
| 8 | + }) |
| 9 | + |
| 10 | + it('should correctly support existing features', () => { |
| 11 | + const { isSupported: textDecoration } = useCssSupports('text-decoration-style', 'blink') |
| 12 | + const { isSupported: transformOrigin } = useCssSupports('transform-origin', '5%') |
| 13 | + const { isSupported: flex } = useCssSupports('display: flex') |
| 14 | + const { isSupported: variable } = useCssSupports('(--foo: red)') |
| 15 | + const { isSupported: selectorHas } = useCssSupports('selector(:has(a))') |
| 16 | + const { isSupported: query } = useCssSupports('(transform-style: preserve) or (-moz-transform-style: preserve) or (-webkit-transform-style: preserve)') |
| 17 | + const { isSupported: doesNotExists } = useCssSupports('doesNotExist') |
| 18 | + |
| 19 | + expect(textDecoration.value).toBe(false) |
| 20 | + expect(transformOrigin.value).toBe(true) |
| 21 | + expect(flex.value).toBe(true) |
| 22 | + expect(variable.value).toBe(true) |
| 23 | + expect(selectorHas.value).toBe(true) |
| 24 | + expect(query.value).toBe(false) |
| 25 | + expect(doesNotExists.value).toBe(false) |
| 26 | + }) |
| 27 | + |
| 28 | + it('should reactively update if condition, prop or value changes', () => { |
| 29 | + const condition = shallowRef('display: flex') |
| 30 | + const { isSupported } = useCssSupports(condition) |
| 31 | + expect(isSupported.value).toBe(true) |
| 32 | + condition.value = 'e18e' |
| 33 | + expect(isSupported.value).toBe(false) |
| 34 | + const prop = shallowRef('transform-origin') |
| 35 | + const value = shallowRef('5%') |
| 36 | + const { isSupported: variable } = useCssSupports(prop, value) |
| 37 | + expect(variable.value).toBe(true) |
| 38 | + value.value = 'e18e' |
| 39 | + expect(variable.value).toBe(false) |
| 40 | + value.value = '5%' |
| 41 | + expect(variable.value).toBe(true) |
| 42 | + prop.value = 'e18e' |
| 43 | + expect(variable.value).toBe(false) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should not treat conditionText as prop when options is set and value is undefined', () => { |
| 47 | + expect(useCssSupports('display: flex').isSupported.value).toBe(true) |
| 48 | + expect(useCssSupports('display: flex', {}).isSupported.value).toBe(true) |
| 49 | + }) |
| 50 | + |
| 51 | + it('should use prop + value instead of condition if value is explicitly undefined', () => { |
| 52 | + expect(useCssSupports('display: flex').isSupported.value).toBe(true) |
| 53 | + expect(useCssSupports('display: flex', undefined).isSupported.value).toBe(false) |
| 54 | + // @ts-expect-error overload catches this issue correctly |
| 55 | + expect(useCssSupports('display: flex', shallowRef(undefined)).isSupported.value).toBe(false) |
| 56 | + }) |
| 57 | +}) |
0 commit comments