Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

splitValueAndUnit.test.ts 1.2 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. })