normalizeProp.spec.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { normalizeClass, parseStringStyle } from '../src'
  2. describe('normalizeClass', () => {
  3. test('handles undefined correctly', () => {
  4. expect(normalizeClass(undefined)).toEqual('')
  5. })
  6. test('handles string correctly', () => {
  7. expect(normalizeClass('foo')).toEqual('foo')
  8. })
  9. test('handles array correctly', () => {
  10. expect(normalizeClass(['foo', undefined, true, false, 'bar'])).toEqual(
  11. 'foo bar'
  12. )
  13. })
  14. test('handles empty array correctly', () => {
  15. expect(normalizeClass([])).toEqual('')
  16. })
  17. test('handles nested array correctly', () => {
  18. expect(normalizeClass(['foo', ['bar'], [['baz']]])).toEqual('foo bar baz')
  19. })
  20. test('handles object correctly', () => {
  21. expect(normalizeClass({ foo: true, bar: false, baz: true })).toEqual(
  22. 'foo baz'
  23. )
  24. })
  25. test('handles empty object correctly', () => {
  26. expect(normalizeClass({})).toEqual('')
  27. })
  28. test('handles arrays and objects correctly', () => {
  29. expect(
  30. normalizeClass(['foo', ['bar'], { baz: true }, [{ qux: true }]])
  31. ).toEqual('foo bar baz qux')
  32. })
  33. test('handles array of objects with falsy values', () => {
  34. expect(
  35. normalizeClass([
  36. { foo: false },
  37. { bar: 0 },
  38. { baz: -0 },
  39. { qux: '' },
  40. { quux: null },
  41. { corge: undefined },
  42. { grault: NaN }
  43. ])
  44. ).toEqual('')
  45. })
  46. test('handles array of objects with truthy values', () => {
  47. expect(
  48. normalizeClass([
  49. { foo: true },
  50. { bar: 'not-empty' },
  51. { baz: 1 },
  52. { qux: {} },
  53. { quux: [] }
  54. ])
  55. ).toEqual('foo bar baz qux quux')
  56. })
  57. // #6777
  58. test('parse multi-line inline style', () => {
  59. expect(
  60. parseStringStyle(`border: 1px solid transparent;
  61. background: linear-gradient(white, white) padding-box,
  62. repeating-linear-gradient(
  63. -45deg,
  64. #ccc 0,
  65. #ccc 0.5em,
  66. white 0,
  67. white 0.75em
  68. );`)
  69. ).toMatchInlineSnapshot(`
  70. {
  71. "background": "linear-gradient(white, white) padding-box,
  72. repeating-linear-gradient(
  73. -45deg,
  74. #ccc 0,
  75. #ccc 0.5em,
  76. white 0,
  77. white 0.75em
  78. )",
  79. "border": "1px solid transparent",
  80. }
  81. `)
  82. })
  83. })