From 2cb93388742fd484fe5fe0b0603b3d78d728077e Mon Sep 17 00:00:00 2001 From: Nicolas BUSUTTIL Date: Wed, 7 Aug 2019 17:33:41 +0200 Subject: [PATCH 1/4] feat(test): implem test --- .eslintcache | 2 +- .idea/workspace.xml | 234 +++++++++----- package.json | 5 +- src/App.test.js | 9 - .../__snapshots__/filmCard.spec.js.snap | 3 + .../film/__tests__/filmCard.spec.js | 25 ++ src/components/film/__tests__/films.spec.js | 42 +++ src/components/film/filmPage.js | 13 +- src/components/film/films.js | 4 +- yarn.lock | 297 +++++++++++++++++- 10 files changed, 518 insertions(+), 116 deletions(-) delete mode 100644 src/App.test.js create mode 100644 src/components/film/__tests__/__snapshots__/filmCard.spec.js.snap create mode 100644 src/components/film/__tests__/filmCard.spec.js create mode 100644 src/components/film/__tests__/films.spec.js diff --git a/.eslintcache b/.eslintcache index a98c56b..9fd2fd9 100644 --- a/.eslintcache +++ b/.eslintcache @@ -1 +1 @@ -[{"/Users/nicolasbusuttil/workspace/react-hooks/src/App.test.js":"1","/Users/nicolasbusuttil/workspace/react-hooks/src/index.js":"2","/Users/nicolasbusuttil/workspace/react-hooks/src/router.js":"3","/Users/nicolasbusuttil/workspace/react-hooks/src/serviceWorker.js":"4","/Users/nicolasbusuttil/workspace/react-hooks/src/utils.js":"5","/Users/nicolasbusuttil/workspace/react-hooks/src/components/counter.js":"6","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmCard.js":"7","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmPage.js":"8","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/films.js":"9","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.actions.js":"10","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.reducer.js":"11","/Users/nicolasbusuttil/workspace/react-hooks/src/components/header/header.js":"12","/Users/nicolasbusuttil/workspace/react-hooks/src/components/NoPageFound.js":"13"},{"size":271,"mtime":1564997330891,"results":"14","hashOfConfig":"15"},{"size":625,"mtime":1564998282282,"results":"16","hashOfConfig":"15"},{"size":325,"mtime":1565174934235,"results":"17","hashOfConfig":"15"},{"size":4951,"mtime":1564992504592,"results":"18","hashOfConfig":"15"},{"size":301,"mtime":1565001944493,"results":"19","hashOfConfig":"15"},{"size":428,"mtime":1564998528369,"results":"20","hashOfConfig":"15"},{"size":445,"mtime":1565174974213,"results":"21","hashOfConfig":"15"},{"size":848,"mtime":1565174728159,"results":"22","hashOfConfig":"15"},{"size":792,"mtime":1565174934229,"results":"23","hashOfConfig":"15"},{"size":1213,"mtime":1565174806166,"results":"24","hashOfConfig":"15"},{"size":1390,"mtime":1565174894270,"results":"25","hashOfConfig":"15"},{"size":292,"mtime":1564998358495,"results":"26","hashOfConfig":"15"},{"size":171,"mtime":1564998482821,"results":"27","hashOfConfig":"15"},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"179i9i5",{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/nicolasbusuttil/workspace/react-hooks/src/App.test.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/index.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/router.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/serviceWorker.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/utils.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/counter.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmCard.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmPage.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/films.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.actions.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.reducer.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/header/header.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/NoPageFound.js",[]] \ No newline at end of file +[{"/Users/nicolasbusuttil/workspace/react-hooks/src/index.js":"1","/Users/nicolasbusuttil/workspace/react-hooks/src/router.js":"2","/Users/nicolasbusuttil/workspace/react-hooks/src/serviceWorker.js":"3","/Users/nicolasbusuttil/workspace/react-hooks/src/utils.js":"4","/Users/nicolasbusuttil/workspace/react-hooks/src/components/counter.js":"5","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmCard.js":"6","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmPage.js":"7","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/films.js":"8","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.actions.js":"9","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.reducer.js":"10","/Users/nicolasbusuttil/workspace/react-hooks/src/components/header/header.js":"11","/Users/nicolasbusuttil/workspace/react-hooks/src/components/NoPageFound.js":"12","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/__tests__/filmCard.spec.js":"13","/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/__tests__/films.spec.js":"14"},{"size":601,"mtime":1565181819435,"results":"15","hashOfConfig":"16"},{"size":322,"mtime":1565181154782,"results":"17","hashOfConfig":"16"},{"size":4926,"mtime":1565175684842,"results":"18","hashOfConfig":"16"},{"size":302,"mtime":1565175684851,"results":"19","hashOfConfig":"16"},{"size":364,"mtime":1565175684649,"results":"20","hashOfConfig":"16"},{"size":453,"mtime":1565181819440,"results":"21","hashOfConfig":"16"},{"size":893,"mtime":1565191862510,"results":"22","hashOfConfig":"16"},{"size":765,"mtime":1565187709278,"results":"23","hashOfConfig":"16"},{"size":1124,"mtime":1565188928576,"results":"24","hashOfConfig":"16"},{"size":1159,"mtime":1565175684757,"results":"25","hashOfConfig":"16"},{"size":304,"mtime":1565181819427,"results":"26","hashOfConfig":"16"},{"size":160,"mtime":1565175684781,"results":"27","hashOfConfig":"16"},{"size":494,"mtime":1565191612892,"results":"28","hashOfConfig":"16"},{"size":1017,"mtime":1565191592379,"results":"29","hashOfConfig":"16"},{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"179i9i5",{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/nicolasbusuttil/workspace/react-hooks/src/index.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/router.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/serviceWorker.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/utils.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/counter.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmCard.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/filmPage.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/films.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.actions.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/store/film.reducer.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/header/header.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/NoPageFound.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/__tests__/filmCard.spec.js",[],"/Users/nicolasbusuttil/workspace/react-hooks/src/components/film/__tests__/films.spec.js",[]] \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6f3fff9..df3de17 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,18 +2,11 @@ - - - - - + - - - - + @@ -28,56 +21,58 @@ - - + + - - - - - + + - - + + - - + + - + + - - + + - - + + - + - - + + - - + + + + + + - - + + - - + + @@ -88,6 +83,7 @@ parserOptions App.s + console.lo @@ -116,17 +112,23 @@ @@ -186,7 +188,8 @@ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1564992470398 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 8521447054cee5589d25af0b7803d05ff5705cad Mon Sep 17 00:00:00 2001 From: Nicolas BUSUTTIL Date: Wed, 7 Aug 2019 17:38:20 +0200 Subject: [PATCH 3/4] fixup! fixup! feat(test): implem test --- .../film/__tests__/__snapshots__/filmCard.spec.js.snap | 3 --- src/components/film/__tests__/filmCard.spec.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 src/components/film/__tests__/__snapshots__/filmCard.spec.js.snap diff --git a/src/components/film/__tests__/__snapshots__/filmCard.spec.js.snap b/src/components/film/__tests__/__snapshots__/filmCard.spec.js.snap deleted file mode 100644 index 2658aed..0000000 --- a/src/components/film/__tests__/__snapshots__/filmCard.spec.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`FilmCard render card 1`] = `ShallowWrapper {}`; diff --git a/src/components/film/__tests__/filmCard.spec.js b/src/components/film/__tests__/filmCard.spec.js index 59c38ca..6b12660 100644 --- a/src/components/film/__tests__/filmCard.spec.js +++ b/src/components/film/__tests__/filmCard.spec.js @@ -20,6 +20,6 @@ describe('FilmCard', () => { const getWrapper = () => shallow(); it('render card', () => { - expect(getWrapper()).toMatchSnapshot(); + expect(getWrapper()); }); }); From fa9de64fa1938344d2ba9cca48d47cf7704ee55e Mon Sep 17 00:00:00 2001 From: Nicolas BUSUTTIL Date: Wed, 7 Aug 2019 18:09:29 +0200 Subject: [PATCH 4/4] fixup! fixup! fixup! feat(test): implem test --- .../film/__tests__/filmCard.spec.js | 23 +++++++------------ src/components/film/__tests__/films.spec.js | 5 ---- src/setupTests.js | 4 ++++ 3 files changed, 12 insertions(+), 20 deletions(-) create mode 100644 src/setupTests.js diff --git a/src/components/film/__tests__/filmCard.spec.js b/src/components/film/__tests__/filmCard.spec.js index 6b12660..13b2bc8 100644 --- a/src/components/film/__tests__/filmCard.spec.js +++ b/src/components/film/__tests__/filmCard.spec.js @@ -1,25 +1,18 @@ import React from 'react'; -import { shallow } from 'enzyme'; - -import Enzyme from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -Enzyme.configure({ adapter: new Adapter() }); +import { mount } from 'enzyme'; import FilmCard from '../filmCard'; describe('FilmCard', () => { - let props = { - film: { - id: 1, - title: 'title', - vote_average: 10, - }, - }; + let props; + beforeEach(() => { + props = { film: {}}; + }); - const getWrapper = () => shallow(); + const getWrapper = () => mount(); it('render card', () => { - expect(getWrapper()); + props.film = {id: 1, title: "aaa"}; + expect(getWrapper().find('h1')).toHaveLength(1); }); }); diff --git a/src/components/film/__tests__/films.spec.js b/src/components/film/__tests__/films.spec.js index 9ac27a8..13ffc86 100644 --- a/src/components/film/__tests__/films.spec.js +++ b/src/components/film/__tests__/films.spec.js @@ -1,11 +1,6 @@ import React from 'react'; import { mount } from 'enzyme'; -import Enzyme from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -Enzyme.configure({ adapter: new Adapter() }); - import { Films } from '../films'; import { filmFetchReducer } from '../store/film.reducer'; import { FETCH_INIT, FETCH_SUCCESS } from '../store/film.actions'; diff --git a/src/setupTests.js b/src/setupTests.js new file mode 100644 index 0000000..fc7b0dc --- /dev/null +++ b/src/setupTests.js @@ -0,0 +1,4 @@ +import Enzyme from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; + +Enzyme.configure({ adapter: new Adapter() });