From 129e27da20020e6ee4909a7be55134ce745a5bf0 Mon Sep 17 00:00:00 2001 From: Zac McClung Date: Sat, 5 Aug 2017 16:41:12 -0600 Subject: [PATCH 1/2] added jest test --- .babelrc | 9 +- .eslintrc.json | 3 +- js/Search.jsx | 4 +- js/__test__/Search.test.jsx | 9 + .../__snapshots__/Search.test.jsx.snap | 351 ++++++++++++++++++ package.json | 2 + 6 files changed, 374 insertions(+), 4 deletions(-) create mode 100644 js/__test__/Search.test.jsx create mode 100644 js/__test__/__snapshots__/Search.test.jsx.snap diff --git a/.babelrc b/.babelrc index 1f51d42f7..adbc9c378 100644 --- a/.babelrc +++ b/.babelrc @@ -11,5 +11,12 @@ ], "plugins": [ "babel-plugin-transform-class-properties" - ] + ], + "env": { + "test": { + "plugins": [ + "transform-es2015-modules-commonjs" + ] + } + } } diff --git a/.eslintrc.json b/.eslintrc.json index 1afa47836..8f3a0812b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,6 +18,7 @@ "env": { "es6": true, "browser": true, - "node": true + "node": true, + "jest": true } } diff --git a/js/Search.jsx b/js/Search.jsx index 1ce244134..fa2a8245f 100644 --- a/js/Search.jsx +++ b/js/Search.jsx @@ -4,7 +4,7 @@ import preload from '../data.json'; class Search extends Component { state = { - searchTerm: 'game' + searchTerm: '' }; handleSearchTermChange = event => { this.setState({ searchTerm: event.target.value }); @@ -13,7 +13,7 @@ class Search extends Component { return (
-

svideo

+

z-video

{ + const component = renderer.create(); + const tree = component.toJSON(); + expect(tree).toMatchSnapshot(); +}); diff --git a/js/__test__/__snapshots__/Search.test.jsx.snap b/js/__test__/__snapshots__/Search.test.jsx.snap new file mode 100644 index 000000000..d3a78c504 --- /dev/null +++ b/js/__test__/__snapshots__/Search.test.jsx.snap @@ -0,0 +1,351 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Search renders correctly 1`] = ` +
+
+

+ z-video +

+ +
+
+
+ Atlanta Show Poster +
+

+ Atlanta +

+

+ ( + 2008–2013 + ) +

+

+ Two cousins, with different views on art versus commerce, on their way up through the Atlanta rap scene; "Earnest 'Earn' Marks," an ambitious college drop-out and his estranged cousin, who suddenly becomes a star. +

+
+
+
+ Billions Show Poster +
+

+ Billions +

+

+ ( + 2016– + ) +

+

+ U.S. Attorney Chuck Rhoades goes after hedge fund king, Bobby "Axe" Axelrod in a battle between two powerful New York figures. +

+
+
+
+ Black Mirror Show Poster +
+

+ Black Mirror +

+

+ ( + 2011– + ) +

+

+ A television anthology series that shows the dark side of life and technology. +

+
+
+
+ Breaking Bad Show Poster +
+

+ Breaking Bad +

+

+ ( + 2008–2013 + ) +

+

+ A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his family's future. +

+
+
+
+ Game of Thrones Show Poster +
+

+ Game of Thrones +

+

+ ( + 2011– + ) +

+

+ Nine noble families fight for control over the mythical lands of Westeros, while a forgotten race returns after being dormant for thousands of years. +

+
+
+
+ Homeland Show Poster +
+

+ Homeland +

+

+ ( + 2011– + ) +

+

+ A bipolar CIA operative becomes convinced a prisoner of war has been turned by al-Qaeda and is planning to carry out a terrorist attack on American soil. +

+
+
+
+ House of Cards Show Poster +
+

+ House of Cards +

+

+ ( + 2013– + ) +

+

+ A Congressman works with his equally conniving wife to exact revenge on the people who betrayed him. +

+
+
+
+ Master of None Show Poster +
+

+ Master of None +

+

+ ( + 2015– + ) +

+

+ The personal and professional life of Dev, a 30-year-old actor in New York. +

+
+
+
+ Narcos Show Poster +
+

+ Narcos +

+

+ ( + 2015– + ) +

+

+ A chronicled look at the criminal exploits of Colombian drug lord Pablo Escobar. +

+
+
+
+ Orange Is the New Black Show Poster +
+

+ Orange Is the New Black +

+

+ ( + 2013– + ) +

+

+ The story of Piper Chapman, a woman in her thirties who is sentenced to fifteen months in prison after being convicted of a decade-old crime of transporting money for her drug-dealing girlfriend. +

+
+
+
+ Silicon Valley Show Poster +
+

+ Silicon Valley +

+

+ ( + 2014– + ) +

+

+ Follows the struggle of Richard Hendricks, a silicon valley engineer trying to build his own company called Pied Piper. +

+
+
+
+ Stranger Things Show Poster +
+

+ Stranger Things +

+

+ ( + 2016– + ) +

+

+ When a young boy disappears, his mother, a police chief, and his friends must confront terrifying forces in order to get him back. +

+
+
+
+ The Americans Show Poster +
+

+ The Americans +

+

+ ( + 2013– + ) +

+

+ Two Soviet intelligence agents pose as a married couple to spy on the American government. +

+
+
+
+ Veep Show Poster +
+

+ Veep +

+

+ ( + 2012– + ) +

+

+ Former Senator Selina Meyer finds that being Vice President of the United States is nothing like she hoped and everything that everyone ever warned her about. +

+
+
+
+ Westworld Show Poster +
+

+ Westworld +

+

+ ( + 2016– + ) +

+

+ Set at the intersection of the near future and the reimagined past, explore a world in which every human appetite, no matter how noble or depraved, can be indulged without consequence. +

+
+
+
+
+`; diff --git a/package.json b/package.json index e74606c20..b46be1221 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "dev": "webpack-dev-server", "format": "prettier --write --single-quote --print-width=120 --parser=flow --tab-width=2 \"js/**/*.{js,jsx}\"", "lint": "eslint **/*.{js,jsx} --quiet", + "test": "jest", + "test:update": "jest -u", "watch": "webpack --watch" }, "dependencies": { From adba64243e0c1af9c54fe4ef296b8e7f1e8aa569 Mon Sep 17 00:00:00 2001 From: Zac McClung Date: Sat, 5 Aug 2017 16:53:44 -0600 Subject: [PATCH 2/2] added shallow testing --- js/ShowCard.jsx | 2 +- js/__test__/Search.test.jsx | 9 +- .../__snapshots__/Search.test.jsx.snap | 450 +++++------------- package.json | 3 + 4 files changed, 129 insertions(+), 335 deletions(-) diff --git a/js/ShowCard.jsx b/js/ShowCard.jsx index 51cdbd2fe..ee94530c4 100644 --- a/js/ShowCard.jsx +++ b/js/ShowCard.jsx @@ -32,7 +32,7 @@ ShowCard.propTypes = { poster: string.isRequired, title: string.isRequired, year: string.isRequired, - description: string.isRequired + description: string.isRequired, }; export default ShowCard; diff --git a/js/__test__/Search.test.jsx b/js/__test__/Search.test.jsx index a5a593914..505913149 100644 --- a/js/__test__/Search.test.jsx +++ b/js/__test__/Search.test.jsx @@ -1,9 +1,10 @@ import React from 'react'; -import renderer from 'react-test-renderer'; +import { shallow } from 'enzyme'; import Search from '../Search'; +// console.log(process.env.NODE_ENV); + test('Search renders correctly', () => { - const component = renderer.create(); - const tree = component.toJSON(); - expect(tree).toMatchSnapshot(); + const component = shallow(); + expect(component).toMatchSnapshot(); }); diff --git a/js/__test__/__snapshots__/Search.test.jsx.snap b/js/__test__/__snapshots__/Search.test.jsx.snap index d3a78c504..6a941234b 100644 --- a/js/__test__/__snapshots__/Search.test.jsx.snap +++ b/js/__test__/__snapshots__/Search.test.jsx.snap @@ -16,336 +16,126 @@ exports[`Search renders correctly 1`] = ` />
-
- Atlanta Show Poster -
-

- Atlanta -

-

- ( - 2008–2013 - ) -

-

- Two cousins, with different views on art versus commerce, on their way up through the Atlanta rap scene; "Earnest 'Earn' Marks," an ambitious college drop-out and his estranged cousin, who suddenly becomes a star. -

-
-
-
- Billions Show Poster -
-

- Billions -

-

- ( - 2016– - ) -

-

- U.S. Attorney Chuck Rhoades goes after hedge fund king, Bobby "Axe" Axelrod in a battle between two powerful New York figures. -

-
-
-
- Black Mirror Show Poster -
-

- Black Mirror -

-

- ( - 2011– - ) -

-

- A television anthology series that shows the dark side of life and technology. -

-
-
-
- Breaking Bad Show Poster -
-

- Breaking Bad -

-

- ( - 2008–2013 - ) -

-

- A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his family's future. -

-
-
-
- Game of Thrones Show Poster -
-

- Game of Thrones -

-

- ( - 2011– - ) -

-

- Nine noble families fight for control over the mythical lands of Westeros, while a forgotten race returns after being dormant for thousands of years. -

-
-
-
- Homeland Show Poster -
-

- Homeland -

-

- ( - 2011– - ) -

-

- A bipolar CIA operative becomes convinced a prisoner of war has been turned by al-Qaeda and is planning to carry out a terrorist attack on American soil. -

-
-
-
- House of Cards Show Poster -
-

- House of Cards -

-

- ( - 2013– - ) -

-

- A Congressman works with his equally conniving wife to exact revenge on the people who betrayed him. -

-
-
-
- Master of None Show Poster -
-

- Master of None -

-

- ( - 2015– - ) -

-

- The personal and professional life of Dev, a 30-year-old actor in New York. -

-
-
-
- Narcos Show Poster -
-

- Narcos -

-

- ( - 2015– - ) -

-

- A chronicled look at the criminal exploits of Colombian drug lord Pablo Escobar. -

-
-
-
- Orange Is the New Black Show Poster -
-

- Orange Is the New Black -

-

- ( - 2013– - ) -

-

- The story of Piper Chapman, a woman in her thirties who is sentenced to fifteen months in prison after being convicted of a decade-old crime of transporting money for her drug-dealing girlfriend. -

-
-
-
- Silicon Valley Show Poster -
-

- Silicon Valley -

-

- ( - 2014– - ) -

-

- Follows the struggle of Richard Hendricks, a silicon valley engineer trying to build his own company called Pied Piper. -

-
-
-
- Stranger Things Show Poster -
-

- Stranger Things -

-

- ( - 2016– - ) -

-

- When a young boy disappears, his mother, a police chief, and his friends must confront terrifying forces in order to get him back. -

-
-
-
- The Americans Show Poster -
-

- The Americans -

-

- ( - 2013– - ) -

-

- Two Soviet intelligence agents pose as a married couple to spy on the American government. -

-
-
-
- Veep Show Poster -
-

- Veep -

-

- ( - 2012– - ) -

-

- Former Senator Selina Meyer finds that being Vice President of the United States is nothing like she hoped and everything that everyone ever warned her about. -

-
-
-
- Westworld Show Poster -
-

- Westworld -

-

- ( - 2016– - ) -

-

- Set at the intersection of the near future and the reimagined past, explore a world in which every human appetite, no matter how noble or depraved, can be indulged without consequence. -

-
-
+ + + + + + + + + + + + + + +
`; diff --git a/package.json b/package.json index b46be1221..0ec2a8d40 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "test:update": "jest -u", "watch": "webpack --watch" }, + "jest": { + "snapshotSerializers": ["jest-serializer-enzyme"] + }, "dependencies": { "axios": "0.16.1", "babel-plugin-dynamic-import-webpack": "1.0.1",