Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

48 rader
1.2 KiB

  1. import * as fc from 'fast-check'
  2. import splitValueAndUnit, { Unit } from './splitValueAndUnit'
  3. it('should exist', () => {
  4. expect(splitValueAndUnit).toBeDefined()
  5. })
  6. it('should be a function', () => {
  7. expect(splitValueAndUnit).toBeFunction()
  8. })
  9. it('should accept 1 argument', () => {
  10. expect(splitValueAndUnit).toHaveLength(1)
  11. })
  12. it('should throw a TypeError when invalid values are supplied', () => {
  13. fc.assert(
  14. fc.property(fc.anything().filter((s) => !['string', 'number'].includes(typeof s)), (s) => {
  15. expect(() => splitValueAndUnit(s)).toThrowError(TypeError)
  16. }),
  17. )
  18. })
  19. it('should parse valid CSS numbers', () => {
  20. fc.assert(
  21. fc.property(
  22. fc.tuple(fc.float(), fc.oneof<Unit>(fc.constant('px'), fc.constant('rem'), fc.constant('%'))),
  23. ([magnitude, unit]) => {
  24. expect(splitValueAndUnit(`${magnitude}${unit}`)).toEqual({
  25. magnitude,
  26. unit,
  27. })
  28. },
  29. ),
  30. )
  31. })
  32. it('should parse numbers as CSS numbers with implicit pixel units', () => {
  33. fc.assert(
  34. fc.property(fc.float(), (magnitude) => {
  35. expect(splitValueAndUnit(magnitude)).toEqual({
  36. magnitude,
  37. unit: 'px',
  38. })
  39. }),
  40. )
  41. })