Skip to content

Commit

Permalink
config babel to support typescript, add a snapshot test code for the …
Browse files Browse the repository at this point in the history
…button component
  • Loading branch information
TrumanH committed Feb 10, 2023
1 parent b66d498 commit 90a9726
Show file tree
Hide file tree
Showing 5 changed files with 871 additions and 16 deletions.
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
['@babel/preset-react', {runtime: 'automatic'}],
'@babel/preset-typescript',
],
};
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "jest",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand All @@ -56,6 +56,12 @@
]
},
"devDependencies": {
"babel-plugin-macros": "^3.1.0"
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"babel-jest": "^29.4.2",
"babel-plugin-macros": "^3.1.0",
"jest": "^29.4.2",
"react-test-renderer": "^18.2.0"
}
}
9 changes: 9 additions & 0 deletions src/components/button/__snapshots__/button.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`changes the class when hovered 1`] = `
<button
className="sc-dkrFOg sc-eDvSVe bAenDU iJPJvM"
>
Test
</button>
`;
11 changes: 11 additions & 0 deletions src/components/button/button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import renderer from 'react-test-renderer';
import Button, { BUTTON_TYPES } from './button.component';

it('changes the class when hovered', () => {
const component = renderer.create(
<Button buttonType={BUTTON_TYPES.inverted}>Test</Button>,
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
}
);
Loading

0 comments on commit 90a9726

Please sign in to comment.