diff --git a/jest.config.js b/jest.config.js index f1518eb..4f4988b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,4 +12,13 @@ module.exports = { __PATH_PREFIX__: ``, }, setupFiles: [`/loadershim.js`], + snapshotSerializers: ["enzyme-to-json/serializer"], + "coverageThreshold": { + "global": { + "branches": 100, + "functions": 100, + "lines": 100, + "statements": 100 + } + } } diff --git a/package.json b/package.json index 8366230..ea627a5 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "author": "Rahul Jain ", "dependencies": { "@primer/octicons-react": "^10.0.0", + "enzyme": "^3.11.0", + "enzyme-adapter-react-16": "^1.15.5", + "enzyme-to-json": "^3.6.1", "gatsby": "^2.23.12", "gatsby-image": "^2.4.9", "gatsby-plugin-google-analytics": "^2.3.11", @@ -35,7 +38,6 @@ "identity-obj-proxy": "3.0.0", "jest": "26.4.2", "prettier": "2.0.5", - "react-test-renderer": "16.13.1", "tailwindcss": "^1.7.6" }, "keywords": [ @@ -49,7 +51,7 @@ "start": "npm run develop", "serve": "gatsby serve", "clean": "gatsby clean", - "test": "jest", + "test": "jest -i -u --coverage", "deploy": "gatsby build --prefix-paths && gh-pages -d public -b master" }, "repository": { diff --git a/src/components/__tests__/__snapshots__/title.test.js.snap b/src/components/__tests__/__snapshots__/title.test.js.snap index 1a82e08..6e07328 100644 --- a/src/components/__tests__/__snapshots__/title.test.js.snap +++ b/src/components/__tests__/__snapshots__/title.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Title renders correctly 1`] = ` +exports[`Title renders title component correctly 1`] = `
@@ -16,14 +16,14 @@ exports[`Title renders correctly 1`] = ` className="outline-none w-24 sm:w-40 mr-10 border-t-0 border-l-0 border-r-0 border solid border-gray-900 py-1 px-2 focus:border-blue-700 prefix" id="title-prefix" onChange={[Function]} - value="Hi 👋, I'm" + value="test_title" />
diff --git a/src/components/__tests__/__snapshots__/work.test.js.snap b/src/components/__tests__/__snapshots__/work.test.js.snap new file mode 100644 index 0000000..1407dd4 --- /dev/null +++ b/src/components/__tests__/__snapshots__/work.test.js.snap @@ -0,0 +1,184 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Work renders work component correctly 1`] = ` +
+
+ Work +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+`; diff --git a/src/components/__tests__/title.test.js b/src/components/__tests__/title.test.js index 4e7a650..191c439 100644 --- a/src/components/__tests__/title.test.js +++ b/src/components/__tests__/title.test.js @@ -1,13 +1,30 @@ import React from "react" -import renderer from "react-test-renderer" import Title from "../title" +import {configure, shallow} from "enzyme"; +import toJson from "enzyme-to-json"; +import Adapter from "enzyme-adapter-react-16"; + +configure({ adapter: new Adapter() }); describe("Title", () => { - it("renders correctly", () => { - const tree = renderer - .create() - .toJSON() - expect(tree).toMatchSnapshot() - }) + const mockEvent = { target: { value: "This is a mock event" } }, + props = { + prefix: { + title: "test_title", + currentWork: "test_currentwork" + }, + data: {title: "test_data"}, + link: {currentWork: "test_currentwork"}, + handlePrefixChange: jest.fn().mockReturnValue({}), + handleLinkChange: jest.fn().mockReturnValue({}), + handleDataChange: jest.fn().mockReturnValue({}), + }; + + it("renders title component correctly", () => { + const component = shallow(<Title {...props}/>); + component.find('input').at(0).simulate('change', mockEvent); + component.find('input').at(1).simulate('change', mockEvent); + expect(toJson(component)).toMatchSnapshot(); + }); }) diff --git a/src/components/__tests__/work.test.js b/src/components/__tests__/work.test.js new file mode 100644 index 0000000..d81f0d7 --- /dev/null +++ b/src/components/__tests__/work.test.js @@ -0,0 +1,32 @@ +import React from "react"; +import { shallow, configure } from 'enzyme'; +import toJson from 'enzyme-to-json'; +import Adapter from 'enzyme-adapter-react-16'; + +import Work from "../work" + +configure({ adapter: new Adapter() }); + +describe("Work", () => { + const props = { + prefix: { + title: "test_title", + currentWork: "test_currentwork" + }, + data: {title: "test_data"}, + link: {currentWork: "test_currentwork"}, + handlePrefixChange: jest.fn().mockReturnValue({}), + handleLinkChange: jest.fn().mockReturnValue({}), + handleDataChange: jest.fn().mockReturnValue({}), + }, + mockEvent = { target: { value: "This is a mock event" } }; + + it("renders work component correctly", () => { + let i; + const component = shallow(<Work {...props}/>); + for (i = 0; i < component.find('input').length; i++) { + component.find('input').at(i).simulate('change', mockEvent); + } + expect(toJson(component)).toMatchSnapshot(); + }); +}); \ No newline at end of file