Skip to content

Commit c30c1b8

Browse files
test: add a test case
1 parent 60c065c commit c30c1b8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/shared/__tests__/normalizeProp.spec.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ describe('normalizeClass', () => {
1313

1414
test('handles string correctly', () => {
1515
expect(normalizeClass('foo')).toEqual('foo')
16-
expect(normalizeClass('foo1 ')).toEqual('foo1')
1716
})
1817

1918
test('handles array correctly', () => {
20-
expect(normalizeClass(['foo ', undefined, true, false, 'bar'])).toEqual(
19+
expect(normalizeClass(['foo', undefined, true, false, 'bar'])).toEqual(
2120
'foo bar',
2221
)
2322
})
2423

24+
test('handles string containing spaces correctly', () => {
25+
expect(normalizeClass('foo1 ')).toEqual('foo1')
26+
expect(normalizeClass(['foo ', ' baz '])).toEqual('foo baz')
27+
})
28+
2529
test('handles empty array correctly', () => {
2630
expect(normalizeClass([])).toEqual('')
2731
})
@@ -104,6 +108,7 @@ describe('normalizeStyle', () => {
104108
test('handles string correctly', () => {
105109
expect(normalizeStyle('foo')).toEqual('foo')
106110
})
111+
107112
test('handles array correctly', () => {
108113
const style: any = normalizeStyle([
109114
`border: 1px solid transparent;
@@ -116,7 +121,9 @@ describe('normalizeStyle', () => {
116121
white 0.75em
117122
);`,
118123
])
124+
119125
expect(style.border).toEqual('1px solid transparent')
126+
120127
expect(style.background).toEqual(`linear-gradient(white, white) padding-box,
121128
repeating-linear-gradient(
122129
-45deg,
@@ -126,6 +133,7 @@ describe('normalizeStyle', () => {
126133
white 0.75em
127134
)`)
128135
})
136+
129137
test('handles object correctly', () => {
130138
const styleObj = {
131139
border: '1px solid transparent',
@@ -145,27 +153,28 @@ describe('normalizeStyle', () => {
145153
})
146154

147155
describe('stringifyStyle', () => {
148-
it('should return empty string for undefined or string styles', () => {
156+
test('should return empty string for undefined or string styles', () => {
149157
expect(stringifyStyle(undefined)).toBe('')
150158
expect(stringifyStyle('')).toBe('')
151159
expect(stringifyStyle('color: blue;')).toBe('')
152160
})
153161

154-
it('should return valid CSS string for normalized style object', () => {
162+
test('should return valid CSS string for normalized style object', () => {
155163
const style = {
156164
color: 'blue',
157165
fontSize: '14px',
158166
backgroundColor: 'white',
159167
opacity: 0.8,
168+
margin: 0,
160169
'--custom-color': 'red',
161170
}
162171

163172
expect(stringifyStyle(style)).toBe(
164-
'color:blue;font-size:14px;background-color:white;opacity:0.8;--custom-color:red;',
173+
'color:blue;font-size:14px;background-color:white;opacity:0.8;margin:0;--custom-color:red;',
165174
)
166175
})
167176

168-
it('should ignore non-string or non-number values in style object', () => {
177+
test('should ignore non-string or non-number values in style object', () => {
169178
const style: any = {
170179
color: 'blue',
171180
fontSize: '14px',

0 commit comments

Comments
 (0)