diff --git a/packages/component-test-utils-react/src/__tests__/shallow-dispatchEvent.spec.js b/packages/component-test-utils-react/src/__tests__/shallow-dispatchEvent.spec.js
index c378a9d..1d80e02 100644
--- a/packages/component-test-utils-react/src/__tests__/shallow-dispatchEvent.spec.js
+++ b/packages/component-test-utils-react/src/__tests__/shallow-dispatchEvent.spec.js
@@ -14,7 +14,7 @@ describe('shallow - trigger/dispatchEvent', () => {
const cmp = shallow();
- cmp.trigger('Click');
+ cmp.trigger('click');
expect(cmp.html()).toBe(
''
@@ -33,7 +33,7 @@ describe('shallow - trigger/dispatchEvent', () => {
const cmp = shallow();
- cmp.dispatchEvent('Click');
+ cmp.dispatchEvent('click');
expect(cmp.html()).toBe(
''
@@ -64,7 +64,7 @@ describe('shallow - trigger/dispatchEvent', () => {
}
const cmp = shallow();
- cmp.dispatchEvent('Click');
+ cmp.dispatchEvent('click');
expect(cmp.html()).toBe(
''
@@ -98,7 +98,7 @@ describe('shallow - trigger/dispatchEvent', () => {
const cmp = shallow();
- cmp.dispatchEvent('Click');
+ cmp.dispatchEvent('click');
expect(cmp.html()).toBe(
''
@@ -125,7 +125,7 @@ describe('shallow - trigger/dispatchEvent', () => {
const cmp = shallow();
- cmp.dispatchEvent('Click');
+ cmp.dispatchEvent('click');
expect(cmp.html()).toBe(
''
diff --git a/packages/component-test-utils-react/src/methods/dispatchEvent.js b/packages/component-test-utils-react/src/methods/dispatchEvent.js
index e5b8832..86f2e02 100644
--- a/packages/component-test-utils-react/src/methods/dispatchEvent.js
+++ b/packages/component-test-utils-react/src/methods/dispatchEvent.js
@@ -1,7 +1,11 @@
const {getHtml} = require('./html');
exports.dispatchEvent = (reactTree, eventName) => {
- if (!reactTree.props[`on${eventName}`]) {
+ const eventNameCaseOk = `${eventName
+ .charAt(0)
+ .toUpperCase()}${eventName.slice(1)}`;
+
+ if (!reactTree.props[`on${eventNameCaseOk}`]) {
throw new Error(
`Cannot dispatch event "${eventName}" on this node : ${getHtml({
...reactTree,
@@ -13,5 +17,5 @@ exports.dispatchEvent = (reactTree, eventName) => {
);
}
- reactTree.props[`on${eventName}`]();
+ reactTree.props[`on${eventNameCaseOk}`]();
};
diff --git a/website/docs/shallow/dispatchEvent.md b/website/docs/shallow/dispatchEvent.md
index c9270dd..6702b3d 100644
--- a/website/docs/shallow/dispatchEvent.md
+++ b/website/docs/shallow/dispatchEvent.md
@@ -22,8 +22,8 @@ const Component = () => {
const cmp = shallow();
-cmp.dispatchEvent('Click');
-// cmp.trigger('Click'); is equivalent
+cmp.dispatchEvent('click');
+// cmp.trigger('click'); is equivalent
expect(cmp.html()).toBe('');
```