Skip to content

Commit

Permalink
test(ProductCard): add test for 'handleClick' method
Browse files Browse the repository at this point in the history
  • Loading branch information
aneurysmjs committed May 2, 2019
1 parent e1fcd56 commit 9b0a8fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app/components/shared/ProductCard/ProductCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class ProductCart extends Component<PropsType> {
hasHover: false,
};

handleClick = () => {

handleClick = (): ProductType => {
const { product } = this.props;
return product;
};

render() {
Expand All @@ -53,15 +54,15 @@ class ProductCart extends Component<PropsType> {
role="presentation"
src={product.image}
alt={product.name}
onClick="handleClick"
onClick={this.handleClick}
className="img-fluid product-card__image"
/>
<img
role="presentation"
data-hovered
src={product.imageHovered}
alt={product.name}
onClick="handleClick"
onClick={this.handleClick}
className="img-fluid product-card__image--hovered"
/>
<figcaption
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/shared/ProductCard/ProductCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ describe('ProductCard', () => {
expect(wrap.instance().props.hasHover).toEqual(false);
expect(wrap.instance().props.hasOverlay).toEqual(false);
});

it('should return the clicked product', () => {
const wrap = shallow(<ProductCard product={product}/>);
expect(wrap.instance().handleClick()).toEqual(product);
});

});

0 comments on commit 9b0a8fe

Please sign in to comment.