|
- import * as fc from 'fast-check'
- import splitValueAndUnit, { Unit, } from './splitValueAndUnit'
-
- it('should exist', () => {
- expect(splitValueAndUnit).toBeDefined()
- })
-
- it('should be a function', () => {
- expect(splitValueAndUnit).toBeFunction()
- })
-
- it('should accept 1 argument', () => {
- expect(splitValueAndUnit).toHaveLength(1)
- })
-
- it('should throw a TypeError when invalid values are supplied', () => {
- fc.assert(
- fc.property(
- fc.anything().filter(s => !['string', 'number'].includes(typeof s)),
- s => {
- expect(() => splitValueAndUnit(s)).toThrowError(TypeError)
- }
- )
- )
- })
-
- it('should parse valid CSS numbers', () => {
- fc.assert(
- fc.property(
- fc.tuple(
- fc.float(),
- fc.oneof<Unit>(
- fc.constant('px'),
- fc.constant('rem'),
- fc.constant('%'),
- )
- ),
- ([magnitude, unit,]) => {
- expect(splitValueAndUnit(`${magnitude}${unit}`)).toEqual({
- magnitude,
- unit,
- })
- }
- )
- )
- })
-
- it('should parse numbers as CSS numbers with implicit pixel units', () => {
- fc.assert(
- fc.property(
- fc.float(),
- magnitude => {
- expect(splitValueAndUnit(magnitude)).toEqual({
- magnitude,
- unit: 'px',
- })
- }
- )
- )
- })
|