Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,5 @@
"presets": [
"env",
"@babel/preset-react"
],
"env": {
"test": {
"plugins": [
"istanbul"
]
},
"production": {
"plugins": [
"istanbul"
]
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ package-lock.json
src/api
build
dist
yarn.lock
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- node
script: npm run test
script: npm test
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
collectCoverage: true,
// Automatically clear mock calls and instances between every test
clearMocks: true,
testPathIgnorePatterns: ['/node_modules/', '/cypress/','build']
};
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"dev": "nodemon --exec babel-node src/app.js ",
"test:watch": "jest --watchAll",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"build": "webpack --mode production ",
"heroku-postbuild": "npm run build",
Expand All @@ -13,13 +14,11 @@
"precommit": "lint-staged",
"test": ""
},

"lint-staged": {
"*.{js,jsx}": [
"git add"
"git add"
]
},

},
"nyc": {
"require": [
"@babel/register"
Expand All @@ -35,13 +34,16 @@
"author": "",
"license": "ISC",
"dependencies": {
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^9.4.0",
"apollo-boost": "^0.4.4",
"babel-preset-env": "^2.0.0-alpha.20",
"bcryptjs": "^2.4.3",
"chai-http": "^4.2.0",
"classnames": "^2.2.6",
"express": "^4.16.3",
"graphql": "^14.5.8",
"jest": "^25.1.0",
"joi": "^14.0.1",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.3.6",
Expand All @@ -52,6 +54,7 @@
"react-apollo": "^3.1.3",
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-test-renderer": "^16.12.0",
"swagger-ui-express": "^4.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/Card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';

const Card = ({ featured_image, title, description, tags, ...rest }) => {
return (
<div className="max-w-sm m-2 rounded overflow-hidden shadow-lg">
<div className="max-w-sm m-2 rounded overflow-hidden shadow-lg" data-testid="card-component">
<img
className="w-full"
src={
Expand Down
29 changes: 29 additions & 0 deletions src/client/components/Card/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import Card from './index';

afterEach(cleanup);

describe('Card Component Unit Testing', () => {
it('Should render component when mounted', () => {
const { getByTestId } = render(
<Card featured_image="test.png" description="testing" title="new component" tags="test" />
);

expect(getByTestId('card-component')).toHaveTextContent('new component');
});

it('Should render component when mounted with conditional prop', () => {
const image = [
{
url: 'sample.png',
},
];
const { getByTestId } = render(
<Card featured_image={image} description="testing" title="new component" tags="test" />
);

expect(getByTestId('card-component')).toHaveTextContent('new component');
});
});
3 changes: 2 additions & 1 deletion src/client/components/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
const Image = ({src, alt, className }) => {
return (
<img
data-testid="image-component"
src={src}
alt={alt}
className={className}
Expand All @@ -14,7 +15,7 @@ const Image = ({src, alt, className }) => {
Image.propTypes = {
src: PropTypes.string,
alt: PropTypes.string,
className: PropTypes.sttring,
className: PropTypes.string,
};

export default Image
16 changes: 16 additions & 0 deletions src/client/components/Image/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react";
import { render, cleanup } from "@testing-library/react";
import "@testing-library/jest-dom"
import Image from "./index";

afterEach(cleanup);

describe("Image Component Unit Testing", () => {
it("Should render component when mounted", () => {
const { getByTestId} = render(
<Image className="bg-gray-500" src='test' alt="test"/>
);

expect(getByTestId("image-component")).toHaveAttribute('alt', 'test')
});
});
Loading