Some jest tests still use removed `doneArg` from vuex_action_helper.js `testAction`
An optional 6th argument named doneArg
used to be to be defined on the vuex helper testAction
.
This could reference a callback to be executed after the testAction
call had been made.
This argument was removed some time ago in !85532 (merged)
However, some tests still call testAction
with this extra argument.
These tests are probably defining expectations that are never verified.
Example
This spec in spec/frontend/emoji/awards_app/store/actions_spec.js
passes a callback to testAction
to verify that Sentry.captureException
has been called.
it('calls Sentry.captureException', async () => {
await testAction(actions.fetchAwards, null, { path: '/awards' }, [], [], () => {
expect(Sentry.captureException).toHaveBeenCalled();
});
});
However, this callback is never invoked in the test. If a change is made that should force the test to fail it still passes.
diff --git a/spec/frontend/emoji/awards_app/store/actions_spec.js b/spec/frontend/emoji/awards_app/store/actions_spec.js
index 23aa7bd5ad7c..5f49ee660887 100644
--- a/spec/frontend/emoji/awards_app/store/actions_spec.js
+++ b/spec/frontend/emoji/awards_app/store/actions_spec.js
@@ -67,7 +67,7 @@ describe('Awards app actions', () => {
it('calls Sentry.captureException', async () => {
await testAction(actions.fetchAwards, null, { path: '/awards' }, [], [], () => {
- expect(Sentry.captureException).toHaveBeenCalled();
+ expect(true).toBe(false);
});
});
});
~/gitlab/gitlab-development-kit/gitlab$ yarn jest /home/malc/gitlab/gitlab-development-kit/gitlab/spec/frontend/emoji/awards_app/store/actions_spec.js
yarn run v1.22.19
$ yarn check-dependencies
$ scripts/frontend/check_dependencies.sh
$ jest --config jest.config.js /home/malc/gitlab/gitlab-development-kit/gitlab/spec/frontend/emoji/awards_app/store/actions_spec.js
PASS spec/frontend/emoji/awards_app/store/actions_spec.js
--8<--
Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
Snapshots: 0 total
Time: 0.957 s
Ran all test suites matching /\/home\/malc\/gitlab\/gitlab-development-kit\/gitlab\/spec\/frontend\/emoji\/awards_app\/store\/actions_spec.js/i.
Done in 2.14s.
Impacted tests
The following files are still calling testAction
with this defunct argument
-
ee/spec/frontend/approvals/stores/modules/license_compliance/actions_spec.js
- !143596 (merged) -
ee/spec/frontend/approvals/stores/modules/project_settings/actions_spec.js
- !143598 (merged) -
ee/spec/frontend/geo_replicable/store/actions_spec.js
- !143601 (merged) -
ee/spec/frontend/security_dashboard/store/modules/vulnerabilities/actions_spec.js
- !143462 (closed) -
spec/frontend/emoji/awards_app/store/actions_spec.js
- !143604 (merged) -
spec/frontend/feature_flags/store/gitlab_user_lists/actions_spec.js
- !143606 (merged) -
spec/frontend/user_lists/store/edit/actions_spec.js
- !143606 (merged) -
spec/frontend/user_lists/store/new/actions_spec.js
- !143606 (merged) -
spec/frontend/user_lists/store/show/actions_spec.js
- !143606 (merged)
Details
diff --git a/spec/frontend/__helpers__/vuex_action_helper.js b/spec/frontend/__helpers__/vuex_action_helper.js
index 94164814879a..7ee83a149fa6 100644
--- a/spec/frontend/__helpers__/vuex_action_helper.js
+++ b/spec/frontend/__helpers__/vuex_action_helper.js
@@ -44,6 +44,7 @@ export default (
stateArg,
expectedMutationsArg = [],
expectedActionsArg = [],
+ doneArg,
) => {
let action = actionArg;
let payload = payloadArg;
@@ -55,6 +56,10 @@ export default (
({ action, payload, state, expectedMutations = [], expectedActions = [] } = actionArg);
}
+ if (typeof doneArg !== 'undefined') {
+ throw new Error('doneArg was passed')
+ }
+
const mutations = [];
const actions = [];
Then listed the test files that fail after making this change:
$ yarn jest --json --outputFile=still_using_doneArg.json `git grep -l testAction`
$ $ jq '[.testResults[] | select(.status == "failed") | .name]' still_using_doneArg.json