Skip to content

Commit

Permalink
Throw error about invalid content property values instead of just log…
Browse files Browse the repository at this point in the history
…ging error to the console. (#1611)
  • Loading branch information
Andarist authored and emmatown committed Nov 6, 2019
1 parent e808fd4 commit 8a896a3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 41 deletions.
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

0 comments on commit 8a896a3

Please sign in to comment.