Skip to content

Commit

Permalink
[Tests] add failing tests for multiple React imports
Browse files Browse the repository at this point in the history
See #31.
  • Loading branch information
ljharb committed Apr 28, 2018
1 parent 157bbf0 commit f380c66
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/fixtures/close2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/fixtures/test-multiple-svg.jsx
@@ -0,0 +1,19 @@
import MySvg from './close.svg';
import MySvg2 from './close.svg';
import MySvg3 from './close2.svg';

export function MyFunctionIcon() {
return <MySvg />;
}

export class MyClassIcon extends React.Component {
render() {
return (
<div>
<MySvg />
<MySvg2 />
<MySvg3 />
</div>
);
}
}
16 changes: 14 additions & 2 deletions test/sanity.js
@@ -1,12 +1,12 @@
import { transformFile } from 'babel-core';

function assertReactImport(result) {
const match = result.code.match(/import React from 'react'/);
const match = result.code.match(/import React from 'react'/g);
if (!match) {
throw new Error('no React import found');
}
if (match.length !== 1) {
throw new Error('more or less than one match found');
throw new Error(`more or less than one match found: ${match}\n${result.code}`);
}
}

Expand All @@ -22,6 +22,18 @@ transformFile('test/fixtures/test.jsx', {
console.log('test/fixtures/test.jsx', result.code);
});

transformFile('test/fixtures/test-multiple-svg.jsx', {
babelrc: false,
presets: ['react'],
plugins: [
'../../src/index',
],
}, (err, result) => {
if (err) throw err;
assertReactImport(result);
console.log('test/fixtures/test-multiple-svg.jsx', result.code);
});

transformFile('test/fixtures/test-no-react.jsx', {
babelrc: false,
presets: ['react'],
Expand Down

0 comments on commit f380c66

Please sign in to comment.