Skip to content

Commit

Permalink
fix(assertions): support non-standard JSX syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jeysal committed Nov 29, 2017
1 parent fb6eb51 commit 81fa923
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const assertionBlockLabels = ['expect', 'then'];
const plugin = (babel: { types: typeof BabelTypes }): PluginObj => {
const assertify = assertifyStatement(babel.types);
const espowerVisitor = createEspowerVisitor(babel, {
embedAst: false,
embedAst: true,
patterns: ['assert(value)'],
});

Expand All @@ -36,9 +36,6 @@ const plugin = (babel: { types: typeof BabelTypes }): PluginObj => {
// Now let espower generate nice power assertions for this labeled statement
espowerVisitor.visitor.Program(path, state);
}

// We're done here, all processing is shallow
path.skip();
}
},
},
Expand Down
17 changes: 17 additions & 0 deletions test/__snapshots__/power-assert.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ exports[`still works if babel-plugin-espower is used for other assertions in the
-1
"
`;

exports[`supports non-standard JSX syntax 1`] = `
" # unknown:2
assert(<div></div>.prop === 'expected')
| |
| false
\\"div\\"
--- [string] 'expected'
+++ [string] <div></div>.prop
@@ -1,8 +1,3 @@
-expected
+div
"
`;
24 changes: 24 additions & 0 deletions test/power-assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,27 @@ test('still works if babel-plugin-espower is used for other assertions in the fi
expect(err.message).toMatchSnapshot();
}
});

test('supports non-standard JSX syntax', () => {
const createElement = jest
.fn()
.mockImplementationOnce(tagName => ({ prop: tagName }));

const { code } = transform(
`import assert from 'power-assert';
expect: (<div></div>).prop === 'expected';`,
{
plugins: [plugin],
presets: ['env', 'react'],
},
);

expect.assertions(1);
try {
new Function('require', 'React', code as string)(require, {
createElement,
});
} catch (err) {
expect(err.message).toMatchSnapshot();
}
});

0 comments on commit 81fa923

Please sign in to comment.