Skip to content

Commit ec82be4

Browse files
authored
Merge pull request #8 from simpletut/simulateEventsWithinTests
simulate click event on button component
2 parents c5a4266 + c7580b9 commit ec82be4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/component/button/spec.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ describe('SharedButton Component', () => {
2323
describe('Renders', () => {
2424

2525
let wrapper;
26+
let mockFunc;
2627
beforeEach(() => {
28+
mockFunc = jest.fn();
2729
const props = {
2830
buttonText: 'Example Button Text',
29-
emitEvent: () => {
30-
31-
}
31+
emitEvent: mockFunc
3232
};
3333
wrapper = shallow(<SharedButton {...props} />);
3434
});
@@ -38,6 +38,13 @@ describe('SharedButton Component', () => {
3838
expect(button.length).toBe(1);
3939
});
4040

41+
it('Should emit callback on click event', () => {
42+
const button = findByTestAtrr(wrapper, 'buttonComponent');
43+
button.simulate('click');
44+
const callback = mockFunc.mock.calls.length;
45+
expect(callback).toBe(1);
46+
});
47+
4148

4249
});
4350

0 commit comments

Comments
 (0)