umputun / remark42

comment engine
https://remark42.com
MIT License
4.77k stars 375 forks source link

Build issue when building frontend #1771

Closed delphij closed 1 month ago

delphij commented 2 months ago

I got the following errors when trying to build frontend with "npm run build" under frontend/apps/remark42:


ERROR in ./app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx:201:15
TS2722: Cannot invoke an object which is possibly 'undefined'.
    199 |     expect(typeof onInputEmail === 'function').toBe(true);
    200 |
  > 201 |     act(() => onInputEmail(makeInputEvent('some@email.com')));
        |               ^^^^^^^^^^^^
    202 |
    203 |     form.simulate('submit');
    204 |

ERROR in ./app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx:201:15
TS2684: The 'this' context of type 'void' is not assignable to method's 'this' of type 'never'.
    199 |     expect(typeof onInputEmail === 'function').toBe(true);
    200 |
  > 201 |     act(() => onInputEmail(makeInputEvent('some@email.com')));
        |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    202 |
    203 |     form.simulate('submit');
    204 |

ERROR in ./app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx:227:15
TS2722: Cannot invoke an object which is possibly 'undefined'.
    225 |     expect(typeof onClick === 'function').toBe(true);
    226 |
  > 227 |     act(() => onClick());
        |               ^^^^^^^
    228 |
    229 |     expect(unsubscribeFromEmailUpdatesMock).toHaveBeenCalled();
    230 |

ERROR in ./app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx:227:15
TS2554: Expected 1 arguments, but got 0.
    225 |     expect(typeof onClick === 'function').toBe(true);
    226 |
  > 227 |     act(() => onClick());
        |               ^^^^^^^^^
    228 |
    229 |     expect(unsubscribeFromEmailUpdatesMock).toHaveBeenCalled();
    230 |

I don't think I know TypeScript enough to confidently contribute a fix, but the following patch seems to fix the build issue and allowed tests to pass:

diff --git a/frontend/apps/remark42/app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx b/frontend/apps/remark42/app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx
index 8aa999ea..77e16fb1 100644
--- a/frontend/apps/remark42/app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx
+++ b/frontend/apps/remark42/app/components/comment-form/__subscribe-by-email/comment-form__subscribe-by-email.test.tsx
@@ -193,7 +193,7 @@ describe('<SubscribeByEmailForm/>', () => {

   it('should send form by paste valid token', async () => {
     const wrapper = createWrapper();
-    const onInputEmail = wrapper.find(Input).prop('onInput');
+    const onInputEmail = wrapper.find(Input).prop('onInput') as Function;
     const form = wrapper.find('form');

     expect(typeof onInputEmail === 'function').toBe(true);
@@ -220,7 +220,7 @@ describe('<SubscribeByEmailForm/>', () => {
   it('should pass throw unsubscribe process', async () => {
     const store = mockStore({ ...initialStore, user: { email_subscription: true } });
     const wrapper = createWrapper(store);
-    const onClick = wrapper.find(Button).prop('onClick');
+    const onClick = wrapper.find(Button).prop('onClick') as Function;

     expect(typeof onClick === 'function').toBe(true);
paskal commented 1 month ago

Good catch! Could you please make a PR with the changes?