|
1 | 1 | import transformCss, { getStylesForProperty } from '..'
|
2 | 2 |
|
3 | 3 | it('transforms numbers', () => {
|
4 |
| - expect( |
5 |
| - transformCss([['top', '0'], ['left', '0'], ['right', '0'], ['bottom', '0']]) |
6 |
| - ).toEqual({ |
7 |
| - top: 0, |
8 |
| - left: 0, |
9 |
| - right: 0, |
10 |
| - bottom: 0, |
11 |
| - }) |
| 4 | + expect(transformCss([['z-index', '0']])).toEqual({ zIndex: 0 }) |
| 5 | +}) |
| 6 | + |
| 7 | +it('warns if missing units on unspecialized transform', () => { |
| 8 | + const consoleSpy = jest |
| 9 | + .spyOn(global.console, 'warn') |
| 10 | + .mockImplementation(() => { |
| 11 | + // Silence the warning from the test output |
| 12 | + }) |
| 13 | + |
| 14 | + transformCss([['top', '1']]) |
| 15 | + expect(consoleSpy).toHaveBeenCalledWith( |
| 16 | + 'Expected style "top: 1" to contain units' |
| 17 | + ) |
| 18 | + |
| 19 | + consoleSpy.mockRestore() |
| 20 | +}) |
| 21 | + |
| 22 | +it('does not warn for unitless 0 length on unspecialized transform', () => { |
| 23 | + const consoleSpy = jest.spyOn(global.console, 'warn') |
| 24 | + |
| 25 | + transformCss([['top', '0']]) |
| 26 | + expect(consoleSpy).not.toHaveBeenCalled() |
| 27 | + |
| 28 | + consoleSpy.mockRestore() |
| 29 | +}) |
| 30 | + |
| 31 | +it('warns if adding etraneous units on unspecialized transform', () => { |
| 32 | + const consoleSpy = jest |
| 33 | + .spyOn(global.console, 'warn') |
| 34 | + .mockImplementation(() => { |
| 35 | + // Silence the warning from the test output |
| 36 | + }) |
| 37 | + |
| 38 | + transformCss([['opacity', '1px']]) |
| 39 | + expect(consoleSpy).toHaveBeenCalledWith( |
| 40 | + 'Expected style "opacity: 1px" to be unitless' |
| 41 | + ) |
| 42 | + |
| 43 | + consoleSpy.mockRestore() |
| 44 | +}) |
| 45 | + |
| 46 | +it('does not warn for unitless 0 length on unitless transform', () => { |
| 47 | + const consoleSpy = jest.spyOn(global.console, 'warn') |
| 48 | + |
| 49 | + transformCss([['opacity', '0']]) |
| 50 | + expect(consoleSpy).not.toHaveBeenCalled() |
| 51 | + |
| 52 | + consoleSpy.mockRestore() |
12 | 53 | })
|
13 | 54 |
|
14 | 55 | it('allows pixels in unspecialized transform', () => {
|
@@ -86,6 +127,13 @@ it('allows negative values in transformed values', () => {
|
86 | 127 | })
|
87 | 128 | })
|
88 | 129 |
|
| 130 | +it('allows uppercase units', () => { |
| 131 | + expect(transformCss([['top', '0PX']])).toEqual({ top: 0 }) |
| 132 | + expect(transformCss([['transform', 'rotate(30DEG)']])).toEqual({ |
| 133 | + transform: [{ rotate: '30deg' }], |
| 134 | + }) |
| 135 | +}) |
| 136 | + |
89 | 137 | it('allows percent values in transformed values', () => {
|
90 | 138 | expect(transformCss([['margin', '10%']])).toEqual({
|
91 | 139 | marginTop: '10%',
|
|
0 commit comments