Skip to content

Commit 10b6ffc

Browse files
committed
Fix runHook twice
1 parent 94649ac commit 10b6ffc

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

__tests__/html2/timestamp/attachmentSendTimeout.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@
6565
fileBlob.name = 'empty.zip';
6666

6767
// WHEN: Sending out the file.
68-
await pageObjects.runHook(({ useSendFiles }) => useSendFiles()([fileBlob]));
68+
await pageObjects.runHook(({ useSendFiles }, numCalled) => {
69+
const sendFiles = useSendFiles();
70+
71+
numCalled || sendFiles([fileBlob]);
72+
});
6973
await pageConditions.numActivitiesShown(2);
7074

7175
// THEN: It should show "Sending".
@@ -92,7 +96,6 @@
9296
updateProps(props => updateIn(props, ['styleOptions', 'sendTimeoutForAttachments'], () => 130000));
9397

9498
// THEN: It should revive the message and show "Sending" again.
95-
expect(pageElements.activities()).toHaveProperty('length', 1);
9699
await expect(pageElements.activityStatuses()[1].innerText).toBe('Sending');
97100
await host.snapshot('local');
98101
},

packages/test/page-object/src/globals/testHelpers/createRunHookActivityMiddleware.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
const RunHook = ({ fn, resolve }) => {
2-
resolve(fn(window.WebChat.hooks));
1+
const { createElement, memo, useRef } = React;
2+
3+
const RunHook = memo(({ fn, resolve }) => {
4+
const numCalledRef = useRef(0);
5+
6+
resolve(fn(window.WebChat.hooks, numCalledRef.current++));
37

48
return false;
5-
};
9+
});
610

711
function createRunHookActivityMiddleware() {
812
return () =>
913
next =>
1014
({ activity, ...others }) => {
1115
if (activity.type === 'event' && activity.name === '__RUN_HOOK') {
12-
return () => !activity.ref.count++ && window.React.createElement(RunHook, activity.value);
16+
return () => !activity.ref.count++ && createElement(RunHook, activity.value);
1317
}
1418

1519
return next({ activity, ...others });

0 commit comments

Comments
 (0)