Fix undefined this in `toMatchInterpolatedText` utility
Summary
When an assertion that uses toMatchInterpolatedText
custom matcher fails, the resulting error message does not indicate why the test has failed.
Steps to reproduce
- Find an assertion that uses
toMatchInterpolatedText
- Change the expected value
- Run the test
Example Project
What is the current bug behavior?
toMatchInterpolatedText
fails with TypeError: Cannot read property 'utils' of undefined
error
What is the expected correct behavior?
The error message should indicate why the test has failed and should look like:
Expected to be: <expected string>
Received: <actual string>
Relevant logs and/or screenshots
Example failure:
TypeError: Cannot read property 'utils' of undefined
23 | `
24 | \n\n
> 25 | Expected: ${this.utils.printExpected(clearReceived)}
| ^
26 | To equal: ${this.utils.printReceived(clearMatch)}
27 | `;
28 |
at message (spec/frontend/__helpers__/matchers/to_match_interpolated_text.js:25:24)
at getMessage (node_modules/expect/build/index.js:173:15)
at processResult (node_modules/expect/build/index.js:289:25)
at Object.toMatchInterpolatedText (node_modules/expect/build/index.js:358:16)
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
Custom matchers are object methods and toMatchInterpolatedText
matcher is currently defined as an arrow function. Object methods should be traditional functions to be able to access appropriate this
.
A possible fix is to change the arrow function to a traditional function.
The other two matchers to_have_sprite_icon.js and to_have_tracking_attributes.js should be fine as they don't access this
.