Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

61 lines
1.3 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(
  15. fc.anything().filter(s => !['string', 'number'].includes(typeof s)),
  16. s => {
  17. expect(() => splitValueAndUnit(s)).toThrowError(TypeError)
  18. }
  19. )
  20. )
  21. })
  22. it('should parse valid CSS numbers', () => {
  23. fc.assert(
  24. fc.property(
  25. fc.tuple(
  26. fc.float(),
  27. fc.oneof<Unit>(
  28. fc.constant('px'),
  29. fc.constant('rem'),
  30. fc.constant('%'),
  31. )
  32. ),
  33. ([magnitude, unit,]) => {
  34. expect(splitValueAndUnit(`${magnitude}${unit}`)).toEqual({
  35. magnitude,
  36. unit,
  37. })
  38. }
  39. )
  40. )
  41. })
  42. it('should parse numbers as CSS numbers with implicit pixel units', () => {
  43. fc.assert(
  44. fc.property(
  45. fc.float(),
  46. magnitude => {
  47. expect(splitValueAndUnit(magnitude)).toEqual({
  48. magnitude,
  49. unit: 'px',
  50. })
  51. }
  52. )
  53. )
  54. })