Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

splitValueAndUnit.test.ts 1.3 KiB

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