Fix Jest spec factories that silently drop caller-supplied options

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

Some Jest spec factories drop an option that the caller passes. The test then runs with the factory default. The scan found 109 such cases.

Background

What the problem is

A spec factory takes one options object and destructures it. The factory lists only some keys. The factory then builds its own provide or propsData block from the keys it listed.

A caller can pass a key that the factory does not list. The factory drops that key. JavaScript raises no error.

Why this matters:

  • The test name describes a state that the test never reaches.
  • Some of these tests pass only because the factory default matches the value that the test asserts.
  • The test suite is green. CI cannot find this problem. A human must read the factory and its calls.
  • These are defects in test coverage. They are not dead weight. The predecessor issue removed dead weight. This issue is different.

Examples

Example 1

File: spec/frontend/clusters_list/components/agent_table_spec.js

The factory on line 54 is:

const createWrapper = ({ propsData = defaultProps, isGroup = false } = {}) => {

The factory builds provide: { isGroup } on line 57.

The call on line 219 is:

createWrapper({
  provide: { projectPath: 'path/to/project' },
  propsData: { agents: [currentAgent] },
});

The factory does not destructure provide. The value projectPath never reaches the component.

Example 2

File: ee/spec/frontend/ai/settings/pages/gitlab_duo_home_spec.js

The factory starts on line 26. It destructures named options. One option is canManageSelfHostedModels = false. The factory builds the provide block itself on line 39.

Two calls pass values inside a provide key. The factory drops them:

  • Line 93 passes provide: { isSaaS: true, isAdminInstanceDuoHome: false }. Neither value reaches the component.
  • Line 187 holds a test named does not render card when `canManageSelfHostedModels` is false. Line 189 passes the value inside provide. The factory drops it. The test passes only because the factory default is already false.

Other calls in the same file pass the option correctly as a top-level key. Line 175 and line 233 both pass canManageSelfHostedModels: true. The file mixes a correct call style and an incorrect call style.

How to find the cases

  • Read each factory and list the keys that it destructures.
  • Read each call to the factory in the same file.
  • Mark every call that passes a key the factory does not list.
  • Run the scan again on current master before you start. The counts above are old.

How to fix

Each case has two possible fixes:

  1. Change the call to pass the option the way the factory expects.
  2. Change the factory to accept the key that the call passes.

The right choice depends on what the test must prove. Read the test name and the assertion first. Then decide.

Do not batch these cases into one large merge request. Each case needs its own decision.

A fix can turn a green test red. The test then exercises the path that its name describes. This is the correct result. It may show a real bug in the component.

Scope and sizing

  • Nobody is working on this now. This issue records the finding.
  • The scan found 109 cases.
  • The work splits by area. It does not split by a fixed batch size.
  • Start with the two examples above. They are confirmed and small.

🤖 AI-generated

Edited by 🤖 GitLab Bot 🤖