Skip to content

Commit

Permalink
Added babel-plugin-styled-components
Browse files Browse the repository at this point in the history
Jest でも styled-components の displayName を参照できるように修正
https://gist.github.com/mrlundis/ca809eea890fa9fd5d98facd51cde731
  • Loading branch information
kotarella1110 committed Sep 11, 2018
1 parent f95c066 commit 4ff1a2b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
54 changes: 37 additions & 17 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,41 @@ const rewireStylelint = (options = {}) => (config, env) => {
return config;
};

module.exports = compose(
rewireStyledComponentsTypescriptPlugin,
rewireStyledComponents,
// rewireTslint({
// emitErrors: false,
// fix: true,
// }),
rewireStylelint({
files: [
'public/**/*.css',
'public/index.html',
module.exports.webpack = () => {
compose(
rewireStyledComponentsTypescriptPlugin,
rewireStyledComponents,
// rewireTslint({
// emitErrors: false,
// fix: true,
// }),
rewireStylelint({
files: [
'public/**/*.css',
'public/index.html',
],
fix: true,
}),
rewireStylelint({
files: ['src/**/*.ts{,x}'],
}),
);
}

module.exports.jest = (config) => {
config.globals['ts-jest'].babelConfig = {
presets: [
'react-app',
],
plugins: [
[
'styled-components',
{
displayName: true,
fileName: false,
},
],
],
fix: true,
}),
rewireStylelint({
files: ['src/**/*.ts{,x}'],
}),
);
};
return config;
}
11 changes: 11 additions & 0 deletions src/App/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ import App from '../App';
it('renders without crashing', () => {
shallow(<App />);
});

it('renders welcome message', () => {
const wrapper = shallow(<App />);
const welcome = 'Welcome to React';
expect(
wrapper
.find('AppTitle')
.children()
.text()
).toBe(welcome);
});
2 changes: 1 addition & 1 deletion src/__snapshots__/storyshots.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports[`Storyshots App Group|App Welcome to Storybook 1`] = `
<img
alt="logo"
className="c2"
src={undefined}
src="logo.svg"
/>
<h1
className="c3"
Expand Down
4 changes: 2 additions & 2 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as enzyme from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16';
import enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

// https://github.com/storybooks/storybook/issues/1011
jest.mock('@storybook/addon-info', () => ({
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs"
"module": "es6",
"target": "es6",
}
}

0 comments on commit 4ff1a2b

Please sign in to comment.