From 44cb60d329e7a9e94c3d51b0ff9ef52592de4246 Mon Sep 17 00:00:00 2001 From: Chamindu Date: Wed, 20 Sep 2023 23:34:30 +0530 Subject: [PATCH 1/4] Add react testing libraries --- package-lock.json | 59 ++++++++++------------------------------------- package.json | 2 +- 2 files changed, 13 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec0a055..0d7d7a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "@stripe/react-stripe-js": "^2.1.2", "@stripe/stripe-js": "^2.0.0", "@testing-library/jest-dom": "^5.16.5", - "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "@types/jest": "^29.5.3", "@types/react": "^18.2.20", @@ -53,6 +52,7 @@ }, "devDependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", + "@testing-library/react": "^14.0.0", "@types/redux-logger": "^3.0.9", "babel-eslint": "^10.1.0", "babel-plugin-macros": "^3.1.0", @@ -5398,7 +5398,6 @@ "version": "9.3.1", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.1.tgz", "integrity": "sha512-0DGPd9AR3+iDTjGoMpxIkAsUihHZ3Ai6CneU6bRRrffXMgzCdlNk43jTrD2/5LT6CBb3MWTP8v510JzYtahD2w==", - "peer": true, "dependencies": { "@babel/code-frame": "^7.10.4", "@babel/runtime": "^7.12.5", @@ -5447,40 +5446,23 @@ } }, "node_modules/@testing-library/react": { - "version": "13.4.0", - "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-13.4.0.tgz", - "integrity": "sha512-sXOGON+WNTh3MLE9rve97ftaZukN3oNf2KjDy7YTx6hcTO2uuLHuCGynMDhFwGw/jYf4OJ2Qk0i4i79qMNNkyw==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-14.0.0.tgz", + "integrity": "sha512-S04gSNJbYE30TlIMLTzv6QCTzt9AqIF5y6s6SzVFILNcNvbV/jU96GeiTPillGQo+Ny64M/5PV7klNYYgv5Dfg==", + "dev": true, "dependencies": { "@babel/runtime": "^7.12.5", - "@testing-library/dom": "^8.5.0", + "@testing-library/dom": "^9.0.0", "@types/react-dom": "^18.0.0" }, "engines": { - "node": ">=12" + "node": ">=14" }, "peerDependencies": { "react": "^18.0.0", "react-dom": "^18.0.0" } }, - "node_modules/@testing-library/react/node_modules/@testing-library/dom": { - "version": "8.20.1", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.20.1.tgz", - "integrity": "sha512-/DiOQ5xBxgdYRC8LNk7U+RWat0S3qRLeIw3ZIkMQ9kkVlRmwD/Eg8k8CqIpD6GW7u20JIUOfMKbxtiLutpjQ4g==", - "dependencies": { - "@babel/code-frame": "^7.10.4", - "@babel/runtime": "^7.12.5", - "@types/aria-query": "^5.0.1", - "aria-query": "5.1.3", - "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.9", - "lz-string": "^1.5.0", - "pretty-format": "^27.0.2" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/@testing-library/user-event": { "version": "13.5.0", "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-13.5.0.tgz", @@ -26517,7 +26499,6 @@ "version": "9.3.1", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.1.tgz", "integrity": "sha512-0DGPd9AR3+iDTjGoMpxIkAsUihHZ3Ai6CneU6bRRrffXMgzCdlNk43jTrD2/5LT6CBb3MWTP8v510JzYtahD2w==", - "peer": true, "requires": { "@babel/code-frame": "^7.10.4", "@babel/runtime": "^7.12.5", @@ -26557,30 +26538,14 @@ } }, "@testing-library/react": { - "version": "13.4.0", - "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-13.4.0.tgz", - "integrity": "sha512-sXOGON+WNTh3MLE9rve97ftaZukN3oNf2KjDy7YTx6hcTO2uuLHuCGynMDhFwGw/jYf4OJ2Qk0i4i79qMNNkyw==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-14.0.0.tgz", + "integrity": "sha512-S04gSNJbYE30TlIMLTzv6QCTzt9AqIF5y6s6SzVFILNcNvbV/jU96GeiTPillGQo+Ny64M/5PV7klNYYgv5Dfg==", + "dev": true, "requires": { "@babel/runtime": "^7.12.5", - "@testing-library/dom": "^8.5.0", + "@testing-library/dom": "^9.0.0", "@types/react-dom": "^18.0.0" - }, - "dependencies": { - "@testing-library/dom": { - "version": "8.20.1", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.20.1.tgz", - "integrity": "sha512-/DiOQ5xBxgdYRC8LNk7U+RWat0S3qRLeIw3ZIkMQ9kkVlRmwD/Eg8k8CqIpD6GW7u20JIUOfMKbxtiLutpjQ4g==", - "requires": { - "@babel/code-frame": "^7.10.4", - "@babel/runtime": "^7.12.5", - "@types/aria-query": "^5.0.1", - "aria-query": "5.1.3", - "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.9", - "lz-string": "^1.5.0", - "pretty-format": "^27.0.2" - } - } } }, "@testing-library/user-event": { diff --git a/package.json b/package.json index 561d110..65959a1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "@stripe/react-stripe-js": "^2.1.2", "@stripe/stripe-js": "^2.0.0", "@testing-library/jest-dom": "^5.16.5", - "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "@types/jest": "^29.5.3", "@types/react": "^18.2.20", @@ -80,6 +79,7 @@ }, "devDependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", + "@testing-library/react": "^14.0.0", "@types/redux-logger": "^3.0.9", "babel-eslint": "^10.1.0", "babel-plugin-macros": "^3.1.0", From bbf732d9f3f30d61b2e7b0239c1d4183b7f1c5e8 Mon Sep 17 00:00:00 2001 From: Chamindu Date: Wed, 20 Sep 2023 23:49:07 +0530 Subject: [PATCH 2/4] Add test cases for Button component --- .../button/__tests__/button.component.test.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/components/button/__tests__/button.component.test.js diff --git a/src/components/button/__tests__/button.component.test.js b/src/components/button/__tests__/button.component.test.js new file mode 100644 index 0000000..9c4134b --- /dev/null +++ b/src/components/button/__tests__/button.component.test.js @@ -0,0 +1,34 @@ +import { render, screen } from '@testing-library/react'; +import Button, { BUTTON_TYPE_CLASSES } from '../button.component'; + +describe('Button tests', () => { + + test('should render base button when nothing is passed', () => { + render(