govuk_publishing_components
govuk_publishing_components copied to clipboard
We might have to remove jQuery from our tests after all
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.
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
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.