Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error about invalid content property values instead of just logging error to the console. #1611

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-spoons-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/serialize': patch
---

Throw error about invalid content property values instead of just logging error to the console.
16 changes: 0 additions & 16 deletions packages/core/__tests__/__snapshots__/warnings.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ exports[`does not warn when valid values are passed for the content property 1`]
/>
`;

exports[`does warn when invalid values are passed for the content property 1`] = `
.emotion-0 {
content: this is not valid;
}

<div
className="emotion-0"
/>
`;

exports[`does warn when invalid values are passed for the content property 2`] = `
<div
className="emotion-0"
/>
`;

exports[`global with css prop 1`] = `null`;

exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ ":first-child /* [flag] */" in a style object 1`] = `
Expand Down
7 changes: 3 additions & 4 deletions packages/core/__tests__/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ const invalidValues = ['this is not valid', '']
it('does warn when invalid values are passed for the content property', () => {
// $FlowFixMe
invalidValues.forEach(value => {
expect(
renderer.create(<div css={{ content: value }} />).toJSON()
).toMatchSnapshot()
expect(console.error).toBeCalledWith(
expect(() =>
renderer.create(<div css={{ content: value }} />)
).toThrowError(
`You seem to be using a value for 'content' without quotes, try replacing it with \`content: '"${value}"'\``
)
})
Expand Down
16 changes: 0 additions & 16 deletions packages/emotion/test/__snapshots__/warnings.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,3 @@ exports[`does not warn when valid values are passed for the content property 1`]
className="emotion-0"
/>
`;

exports[`does warn when invalid values are passed for the content property 1`] = `
.emotion-0 {
content: this is not valid;
}

<div
className="emotion-0"
/>
`;

exports[`does warn when invalid values are passed for the content property 2`] = `
<div
className="emotion-0"
/>
`;
7 changes: 3 additions & 4 deletions packages/emotion/test/warnings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ const invalidValues = ['this is not valid', '']

it('does warn when invalid values are passed for the content property', () => {
invalidValues.forEach(value => {
expect(
renderer.create(<div className={css({ content: value })} />).toJSON()
).toMatchSnapshot()
expect(console.error).toBeCalledWith(
expect(() =>
renderer.create(<div className={css({ content: value })} />)
).toThrowError(
`You seem to be using a value for 'content' without quotes, try replacing it with \`content: '"${value}"'\``
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/serialize/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if (process.env.NODE_ENV !== 'production') {
(value.charAt(0) !== value.charAt(value.length - 1) ||
(value.charAt(0) !== '"' && value.charAt(0) !== "'")))
) {
console.error(
throw new Error(
`You seem to be using a value for 'content' without quotes, try replacing it with \`content: '"${value}"'\``
)
}
Expand Down