Skip to content

Commit

Permalink
Correct rendering of falsy values
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyAlford committed Mar 22, 2019
1 parent 47f7628 commit 9dc6982
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/components/JsxParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class JsxParser extends Component {
case 'JSXElement':
return this.parseElement(expression)
case 'JSXText':
return (expression.value || '')
return expression.value
case 'JSXAttribute':
if (expression.value === null) return true
return this.parseExpression(expression.value)
Expand Down
5 changes: 5 additions & 0 deletions source/components/JsxParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ describe('JsxParser Component', () => {
expect(console.error).toHaveBeenCalledTimes(1)
expect(console.error.mock.calls[0][0]).toMatch(/unrecognized in this browser/)
})
it('renders falsy expressions correctly', () => {
const jsx = '<b>{false}{undefined}{0}{null}{[]}</b>'
const wrapper = shallow(<JsxParser jsx={jsx} renderInWrapper={false} />)
expect(wrapper.html()).toBe('<b>0</b>')
})
it('skips over DOCTYPE, html, head, and div if found', () => {
const { rendered } = render(
<JsxParser jsx={'<!DOCTYPE html><html><head></head><body><h1>Test</h1><p>Another Text</p></body></html>'} />
Expand Down

0 comments on commit 9dc6982

Please sign in to comment.