Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

stringify.test.ts 1.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import * as fc from 'fast-check'
  2. import * as fcArb from '../../utilities/fast-check/arbitraries'
  3. import stringify from './stringify'
  4. it('should exist', () => {
  5. expect(stringify).toBeDefined()
  6. })
  7. it('should be a function', () => {
  8. expect(stringify).toBeFunction()
  9. })
  10. it('should accept 1 argument', () => {
  11. expect(stringify).toHaveLength(1)
  12. })
  13. it('should return a string value', () => {
  14. fc.assert(
  15. fc.property(
  16. fc.anything(),
  17. v => {
  18. expect(stringify(v)).toBeString()
  19. }
  20. )
  21. )
  22. })
  23. describe('on arguments', () => {
  24. it('should consider `undefined` as empty string', () => {
  25. expect(stringify(undefined)).toBe('')
  26. })
  27. it('should consider `null` as empty string', () => {
  28. expect(stringify(null)).toBe('')
  29. })
  30. it('should stringify non-objects', () => {
  31. fc.assert(
  32. fc.property(
  33. fcArb.nonObject(),
  34. fc.string(),
  35. v => {
  36. expect(stringify(v)).toBe(String(v))
  37. }
  38. )
  39. )
  40. })
  41. it('should stringify objects', () => {
  42. fc.assert(
  43. fc.property(
  44. fc.object(),
  45. v => {
  46. expect(stringify(v)).toBe(JSON.stringify(v))
  47. }
  48. )
  49. )
  50. })
  51. describe('on arrays', () => {
  52. it('should stringify empty arrays', () => {
  53. fc.assert(
  54. fc.property(
  55. fc.array(fcArb.nonObject(), 0),
  56. v => {
  57. expect(stringify(v)).toBe('')
  58. }
  59. )
  60. )
  61. })
  62. it('should stringify arrays with single values', () => {
  63. fc.assert(
  64. fc.property(
  65. fc.array(fcArb.nonObject(), 1, 1),
  66. v => {
  67. expect(stringify(v)).toBe(String(v[0]))
  68. }
  69. )
  70. )
  71. })
  72. it('should stringify arrays with 2 or more values', () => {
  73. fc.assert(
  74. fc.property(
  75. fc.array(fcArb.nonObject(), 2, 20),
  76. v => {
  77. expect(stringify(v)).toContain(',')
  78. }
  79. )
  80. )
  81. })
  82. })
  83. })