Skip to content

Commit

Permalink
feat(test): add mocking CSS modules JEST
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Grillo committed Sep 16, 2020
1 parent dc3c8cc commit b0716d6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 93 deletions.
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
module.exports = {
setupFilesAfterEnv: ['<rootDir>test/setup.js'],
collectCoverage: true,
Expand All @@ -17,8 +18,9 @@ module.exports = {
'^.+\\.(js|jsx)$': 'babel-jest',
},
verbose: true,
transformIgnorePatterns: ['/node_modules/(?!roi-.*)'],
transformIgnorePatterns: ['/node_modules/(?!@cdg.*)'],
moduleNameMapper: {
'.svg': '<rootDir>/test/__mocks__/fileMock.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js',
'\\.(css|less|scss)$': 'identity-obj-proxy',
},
};
105 changes: 39 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.4",
"enzyme-to-json": "^3.5.0",
"eslint": "^7.8.1",
"eslint": "^7.9.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-react": "^7.20.6",
Expand All @@ -66,9 +66,9 @@
"identity-obj-proxy": "^3.0.0",
"ignore-styles": "^5.0.1",
"jest": "^26.4.2",
"mini-css-extract-plugin": "^0.11.1",
"mini-css-extract-plugin": "^0.11.2",
"node-sass": "^4.14.1",
"postcss-loader": "^4.0.1",
"postcss-loader": "^4.0.2",
"postcss-preset-env": "^6.7.0",
"postcss-smart-import": "^0.7.6",
"react": "^16.13.1",
Expand Down
44 changes: 22 additions & 22 deletions test/__snapshots__/example.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

exports[`component snapshoot render with all props 1`] = `
<li
className="list-item js--hover"
className="listItem js--hover"
>
<figure
className="list-figure"
className="listItem__figure"
>
<figcaption
className="list-figcaption"
className="listItem__figcaption"
>
<h3
className="list-item__title"
className="listItem__title"
>
Test title
</h3>
<h4
className="list-item__sub-title"
className="listItem__subTitle"
>
Subtitle test
</h4>
</figcaption>
<div
className="list-item__img-fix"
className="listItem__imgFix"
style={
Object {
"backgroundImage": "url(https://source.unsplash.com/random)",
Expand All @@ -31,54 +31,54 @@ exports[`component snapshoot render with all props 1`] = `
/>
<img
alt="Test title image"
className="list-item__img"
className="listItem__img"
src="https://source.unsplash.com/random"
/>
<div
className="list-item__content"
className="listItem__content"
>
<p
className="list-item__description"
className="listItem__description"
>
Aenean vitae neque ultricies, egestas eros non, bibendum purus.
Suspendisse sodales quam non lectus imperdiet dignissim.
</p>
<button
className="list-item__action"
className="listItem__action"
>
Call now
</button>
</div>
<span
className="list-item__extra"
className="listItem__extra"
/>
</figure>
</li>
`;

exports[`component snapshoot render without props 1`] = `
<li
className="list-item js--hover"
className="listItem js--hover"
>
<figure
className="list-figure"
className="listItem__figure"
>
<figcaption
className="list-figcaption"
className="listItem__figcaption"
>
<h3
className="list-item__title"
className="listItem__title"
>
Test title
</h3>
<h4
className="list-item__sub-title"
className="listItem__subTitle"
>
Subtitle test
</h4>
</figcaption>
<div
className="list-item__img-fix"
className="listItem__imgFix"
style={
Object {
"backgroundImage": "url(https://source.unsplash.com/random)",
Expand All @@ -87,26 +87,26 @@ exports[`component snapshoot render without props 1`] = `
/>
<img
alt="Test title image"
className="list-item__img"
className="listItem__img"
src="https://source.unsplash.com/random"
/>
<div
className="list-item__content"
className="listItem__content"
>
<p
className="list-item__description"
className="listItem__description"
>
Aenean vitae neque ultricies, egestas eros non, bibendum purus.
Suspendisse sodales quam non lectus imperdiet dignissim.
</p>
<button
className="list-item__action"
className="listItem__action"
>
Call now
</button>
</div>
<span
className="list-item__extra"
className="listItem__extra"
/>
</figure>
</li>
Expand Down

0 comments on commit b0716d6

Please sign in to comment.