govuk_publishing_components icon indicating copy to clipboard operation
govuk_publishing_components copied to clipboard

We might have to remove jQuery from our tests after all

Open andysellick opened this issue 2 years ago • 2 comments

Dependabot just raised bump jasmine-core to 4.3.0, which is producing several errors in the jasmine/JavaScript tests like this:

Uncaught TypeError: jasmine.util.argsToArray is not a function thrown

The gem relies on a hard coded local copy of jasmine-jquery to provide helper functions when running tests. This in turn relies upon a function inside jasmine-core called jasmine.util.argsToArray(), which was unfortunately removed in the 4.3.0 release.

Upgrading jasmine-jquery seemed like the logical first step, but the latest version still has this problem. Furthermore, the owners of the repo are now unable to maintain it and are seeking someone to take over responsibility.

I've fixed this for now by hard coding the argsToArray() function inside our local copy of jasmine-jquery, but this is obviously not an ideal solution for the future. We're probably going to need to remove our dependency on this package, either by removing jQuery from all of our tests or by finding another way.

andysellick avatar Aug 11 '22 09:08 andysellick

We've discovered that finder-frontend doesn't use jasmine-jquery for its tests, which prompted us to investigate what jasmine-jquery is doing for us. It looks like it adds extra matchers (e.g. .toBeVisible(), .toBeHidden()) on tests to make it easier to write them. However we seem to be only using these extra matchers on a few tests, so we should be able to change those tests and remove jasmine-jquery. Here are the matchers it provides, that we will have to replace: https://www.npmjs.com/package/jasmine-jquery#jquery-matchers

AshGDS avatar Sep 01 '22 14:09 AshGDS

I've used Cheerio before with Jest to create a jQuery like API to query in tests, I wonder if it could be used here.

hannalaakso avatar Sep 29 '22 10:09 hannalaakso