Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ujs: migrate to TypeScript #225

Merged
merged 2 commits into from
Apr 16, 2024
Merged

ujs: migrate to TypeScript #225

merged 2 commits into from
Apr 16, 2024

Conversation

liamwhite
Copy link
Contributor

@liamwhite liamwhite commented Apr 15, 2024

This moves all of the ujs events convenience library into TypeScript. There should be no substantial changes to the logic here, but two bugs were discovered during testing and fixed:

  1. Incorrect use of target where input was intended.
    $$('[disabled][data-disable-with][data-enable-with]', target).forEach(input => {
      // ...
      input.innerHTML = target.dataset.enableWith;
      //                ^^^^^^ input
    }
  2. HTMLFormElement's method property is restricted, so the final 'POST' case is unreachable here:
     method: (target.dataset.method || target.method || 'POST').toUpperCase(),

This has 100% test coverage in unit tests and has also been manually integration tested.

};
}

jest.spyOn(global, 'fetch').mockImplementation(multipleChoicesResponse as any);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use mockResolvedValue with the newly created Response instance to avoid the use of any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up changing this to mockReturnValue. I need to defeat the type system so that there is no async code, because the function I am testing cannot return anything.

@liamwhite liamwhite merged commit 3cba72e into master Apr 16, 2024
4 checks passed
@liamwhite liamwhite deleted the ujs-ts branch April 16, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants