codeant-ai-for-open-source[bot] commented on code in PR #37112:
URL: https://github.com/apache/superset/pull/37112#discussion_r2731813907
##########
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx:
##########
@@ -600,11 +626,25 @@ test('Should render RowCountLabel when row limit is hit,
and hide it otherwise',
);
expect(screen.queryByTestId('warning')).not.toBeInTheDocument();
+
+ mockUseUiConfig.mockRestore();
});
Review Comment:
**Suggestion:** The tests call `mockUseUiConfig.mockRestore()`, but
`useUiConfig` was mocked with `jest.fn()` at module scope, and `mockRestore` is
not available on plain jest mocks (it's only available on spies created by
`jest.spyOn`). Calling `mockRestore()` will throw a TypeError at runtime.
Restore the mock to the module default by calling
`mockUseUiConfig.mockReturnValue(...)` with the original default config
instead. [possible bug]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ SliceHeader.test.tsx fails with TypeError in CI.
- ⚠️ CI pipeline flags failing unit tests.
- ⚠️ Developers blocked merging by failing tests.
```
</details>
```suggestion
mockUseUiConfig.mockReturnValue({
hideTitle: false,
hideTab: false,
hideNav: false,
hideChartControls: false,
emitDataMasks: false,
showRowLimitWarning: false,
});
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Run the SliceHeader unit tests: execute Jest for this file, e.g. `yarn
test
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx
-t "Should
render RowCountLabel when row limit is hit, and hide it otherwise"`. This
loads the test
module and executes the test body starting at
`superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx:568`
(test
"Should render RowCountLabel when row limit is hit, and hide it otherwise").
2. Inside that test, the local typed alias is created and the mock is
overridden at
`...SliceHeader.test.tsx:601` (`const mockUseUiConfig = useUiConfig as
jest.MockedFunction<typeof useUiConfig>;
mockUseUiConfig.mockReturnValue({...})`), setting
a per-test return value for the module-scoped jest.fn() mock.
3. At the end of the test the code calls `mockUseUiConfig.mockRestore()` at
`superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx:631`.
Because
`useUiConfig` was mocked at module scope with `jest.fn()` (via
`jest.mock('src/components/UiConfigContext', () => ({ useUiConfig:
jest.fn().mockReturnValue(...) }))`), the resulting `mockUseUiConfig` is a
plain jest.fn()
spy, which does not implement `mockRestore()`. Jest will raise a TypeError
("mockUseUiConfig.mockRestore is not a function") when that line is executed.
4. Observable failure: the single test run or the whole test suite will
crash/fail with a
TypeError at the call site (`...SliceHeader.test.tsx:631`), causing CI or
local test runs
to show a failing test run. The correct way to restore the module-level mock
is to call
`mockUseUiConfig.mockReturnValue(originalDefault)` or use
`jest.resetAllMocks()` /
`jest.restoreAllMocks()` depending on mocking approach. If the existing
pattern (module
mock via jest.fn()) is intentional, the `mockRestore()` call is a bug and
must be replaced
as suggested.
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx
**Line:** 631:631
**Comment:**
*Possible Bug: The tests call `mockUseUiConfig.mockRestore()`, but
`useUiConfig` was mocked with `jest.fn()` at module scope, and `mockRestore` is
not available on plain jest mocks (it's only available on spies created by
`jest.spyOn`). Calling `mockRestore()` will throw a TypeError at runtime.
Restore the mock to the module default by calling
`mockUseUiConfig.mockReturnValue(...)` with the original default config instead.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]