Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
As written at
assets/js/theme/global/jquery-migrate.js
:This is also true for the testing environment. Foundation 5.5 still expects jQuery 2.x, and the need for jquery-migrate is the same.
However, Foundation is used at
assets/js/test-unit/theme/global/modal.spec.js
, but jquery-migrate is not loaded.The purpose of this PR is to fix this situation. It includes the missing jquery-migrate import to this test, before Foundation is used.
Why this needs to be fixed? (easy to reproduce)
We stumbled upon this problem when adding our own tests to our custom theme. It is very easy to reproduce.
➡️ Simply save the following test specification as
assets/js/test-unit/theme/common/sample.spec.js
:➡️ Now, run
npx karma start
(ornpx grunt karma
) to run the tests. It will fail.Why does it fail?
When we call
foundation($('document'));
, it internally calls$(window).load()
- but theload
event has been removed in newer jQuery versions. The$(window).load()
Foundation code would work with old jQuery (or modified by jquery-migrate), but in modern jQuery it will call the Ajax load function instead!Even though we are importing jquery-migrate, the Modal test ran before, and Foundation has been somehow tied to a jQuery instance which does not have the jquery-migrate changes.
➡️ Now, apply the simple change from this PR, and run the tests again. It will succeed!
Why does it suceed?
When Foundation is initialized at Modal testing, jquery-migrate changes were already applied, and thus Foundation gets tied to a jQuery instance properly modified, and works as expected at all the following tests.
In fact, a separate test specification is not required to reproduce the issue. We can just add a few lines to the beginning of the Modal test spec, and it will also reveal the problem.
Screenshots
⬇️ Running the test which uses Foundation, before this PR fix:
⬇️ Running the test which uses Foundation, after this PR fix: