Skip to content

Commit

Permalink
fix: properly deindent and trim code and output
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed May 16, 2017
1 parent 34b3799 commit eb60549
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function toTestArray(tests) {

function toTestConfig({testConfig, index, plugin, pluginName, fixtures}) {
if (typeof testConfig === 'string') {
testConfig = {code: stripIndent(testConfig).trim()}
testConfig = {code: testConfig}
}
const {
title,
Expand All @@ -121,8 +121,8 @@ function toTestConfig({testConfig, index, plugin, pluginName, fixtures}) {
return merge({}, testConfig, {
babelOptions: {plugins: [plugin]},
title: fullTitle,
code: code.trim(),
output: output.trim(),
code: stripIndent(code).trim(),
output: stripIndent(output).trim(),
})
}

Expand Down
19 changes: 19 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ test(`throws invariant if there's no code`, () => {
).toThrowErrorMatchingSnapshot()
})

test('trims and deindents code and output', () => {
const tests = [
{
code: `
var someCode = 'cool';
`,
output: `
var someCode = 'cool';
`,
},
]
pluginTester(getOptions({tests}))
expect(equalSpy).toHaveBeenCalledWith(
`var someCode = 'cool';`,
`var someCode = 'cool';`,
expect.any(String),
)
})

test('can get a code and output fixture that is an absolute path', () => {
const tests = [
{
Expand Down

0 comments on commit eb60549

Please sign in to comment.