-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ handle events shallow configuration for react
- Loading branch information
1 parent
8ec125d
commit f2d4ca3
Showing
8 changed files
with
112 additions
and
47 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/component-test-utils-react/src/__tests__/shallow-event.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const {shallow} = require('../shallow'); | ||
const React = require('react'); | ||
|
||
describe('shallow - event', () => { | ||
const ComponentParent = ({product, onProductAddedToBasket}) => { | ||
return ( | ||
<button type="button" onClick={() => onProductAddedToBasket(product)}/> | ||
); | ||
}; | ||
|
||
it('it should call productAddedToBasket event', () => { | ||
const productAddedToBasketSpy = jest.fn(); | ||
const product = {price: 20}; | ||
const cmp = shallow(<ComponentParent product={product}/>, { | ||
events: { | ||
productAddedToBasket: productAddedToBasketSpy | ||
} | ||
}); | ||
|
||
expect(productAddedToBasketSpy).not.toHaveBeenCalled(); | ||
|
||
cmp.dispatchEvent('click'); | ||
|
||
expect(productAddedToBasketSpy).toHaveBeenCalledWith(product); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters