Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle shorthands in attributes correctly
- Loading branch information
Showing
5 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/__tests__/__snapshots__/attributes-shorthand.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`JavaScript output: transformed source code 1`] = ` | ||
"'use strict'; | ||
// To prevent warnings in console from react | ||
const Custom = () => null; | ||
const test = 10; | ||
module.exports = <Custom first-attribute={true} second-attribute={true} positive={true} negative={false} check={true}><Custom one={true} two={true} /></Custom>;" | ||
`; | ||
|
||
exports[`html output: generated html 1`] = `null`; | ||
|
||
exports[`static html output: static html 1`] = `""`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
// To prevent warnings in console from react | ||
const Custom = () => null | ||
const test = 10 | ||
|
||
module.exports = pug` | ||
Custom( | ||
first-attribute | ||
second-attribute | ||
positive=true | ||
negative=false | ||
check | ||
) | ||
Custom(one two) | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import testHelper from './test-helper'; | ||
|
||
testHelper(__dirname + '/attributes-shorthand.input.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import {transform} from 'babel-core'; | ||
import renderer from 'react-test-renderer'; | ||
import transformReactPug from '../'; | ||
|
||
const transformationOptions = { | ||
babelrc: false, | ||
plugins: [transformReactPug], | ||
} | ||
|
||
const transformer = (code) => { | ||
return transform(`pug\`${code}\``, transformationOptions).code | ||
} | ||
|
||
const ExpectedError = /Unescaped attributes/ | ||
|
||
test('throws error when pass string', () => { | ||
const wrapped = () => transformer(` | ||
div(name!="hello") | ||
`) | ||
|
||
expect(wrapped).toThrowError(ExpectedError) | ||
}) | ||
|
||
test('throws error when pass variable', () => { | ||
const wrapped = () => transformer(` | ||
- const variable = 'value' | ||
div(name!=variable.toString()) | ||
`) | ||
|
||
expect(wrapped).toThrowError(ExpectedError) | ||
}) | ||
|
||
test('does not throw error when pass variable or just string', () => { | ||
const wrapped = () => transformer(` | ||
- const variable = 'value' | ||
div(data-string="hello" data-variable=variable) | ||
`) | ||
|
||
expect(wrapped).not.toThrowError(ExpectedError) | ||
}) | ||
|
||
test('does not throw error when pass boolean variables', () => { | ||
const wrapped = () => transformer(` | ||
div(data-first data-second data-third) | ||
`) | ||
|
||
expect(wrapped).not.toThrowError(ExpectedError) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters