Skip to content

Commit 5ba4703

Browse files
committed
move tests to error describe block
1 parent 2a2f53b commit 5ba4703

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

packages/tailwindcss/src/css-parser.test.ts

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,28 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
329329
])
330330
})
331331

332+
it('should parse a custom property with an empty value', () => {
333+
expect(parse('--foo:;')).toEqual([
334+
{
335+
kind: 'declaration',
336+
property: '--foo',
337+
value: '',
338+
important: false,
339+
},
340+
])
341+
})
342+
343+
it('should parse a custom property with a space value', () => {
344+
expect(parse('--foo: ;')).toEqual([
345+
{
346+
kind: 'declaration',
347+
property: '--foo',
348+
value: '',
349+
important: false,
350+
},
351+
])
352+
})
353+
332354
it('should parse a custom property with a block including nested "css"', () => {
333355
expect(
334356
parse(css`
@@ -1041,34 +1063,6 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
10411063
},
10421064
])
10431065
})
1044-
1045-
// TODO: These should probably be errors in some cases?
1046-
it('discards invalid declarations', () => {
1047-
// This shouldn't parse as a custom property declaration
1048-
expect(parse(`--foo`)).toEqual([])
1049-
1050-
// This shouldn't parse as a rule followed by a declaration
1051-
expect(parse(`@plugin "foo" {};`)).toEqual([
1052-
{
1053-
kind: 'at-rule',
1054-
name: '@plugin',
1055-
params: '"foo"',
1056-
nodes: [],
1057-
},
1058-
])
1059-
1060-
// This shouldn't parse as consecutive declarations
1061-
expect(parse(`;;;`)).toEqual([])
1062-
1063-
// This shouldn't parse as a rule with a declaration inside of it
1064-
expect(parse(`.foo { bar }`)).toEqual([
1065-
{
1066-
kind: 'rule',
1067-
selector: '.foo',
1068-
nodes: [],
1069-
},
1070-
])
1071-
})
10721066
})
10731067

10741068
describe('errors', () => {
@@ -1125,5 +1119,39 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
11251119
`),
11261120
).toThrowErrorMatchingInlineSnapshot(`[Error: Unterminated string: "Hello world!;"]`)
11271121
})
1122+
1123+
it('should error when incomplete custom properties are used', () => {
1124+
expect(() => parse('--foo')).toThrowErrorMatchingInlineSnapshot(
1125+
`[Error: Invalid custom property, expected a value]`,
1126+
)
1127+
})
1128+
1129+
it('should error when incomplete custom properties are used inside rules', () => {
1130+
expect(() => parse('.foo { --bar }')).toThrowErrorMatchingInlineSnapshot(
1131+
`[Error: Invalid custom property, expected a value]`,
1132+
)
1133+
})
1134+
1135+
it('should error when a declaration is incomplete', () => {
1136+
expect(() => parse('.foo { bar }')).toThrowErrorMatchingInlineSnapshot(
1137+
`[Error: Invalid declaration: \`bar\`]`,
1138+
)
1139+
})
1140+
1141+
it('should error when a semicolon exists after an at-rule with a body', () => {
1142+
expect(() => parse('@plugin "foo" {} ;')).toThrowErrorMatchingInlineSnapshot(
1143+
`[Error: Unexpected semicolon]`,
1144+
)
1145+
})
1146+
1147+
it('should error when consecutive semicolons exist', () => {
1148+
expect(() => parse(';;;')).toThrowErrorMatchingInlineSnapshot(`[Error: Unexpected: \`;;;\`]`)
1149+
})
1150+
1151+
it('should error when consecutive semicolons exist after a declaration', () => {
1152+
expect(() => parse('.foo { color: red;;; }')).toThrowErrorMatchingInlineSnapshot(
1153+
`[Error: Unexpected: \`;;;\`]`,
1154+
)
1155+
})
11281156
})
11291157
})

0 commit comments

Comments
 (0)