-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A warning thrown with jest #5371
Comments
my stack trace for this issue
|
Same issue when updating from version |
Hey everyone, Thanks for reporting the issue. We'll fix it. |
Hey guys, I've created temporary patch for this issue: File: diff --git a/node_modules/native-base/lib/commonjs/core/color-mode/hooks.js b/node_modules/native-base/lib/commonjs/core/color-mode/hooks.js
index 8e28efe..68490c8 100644
--- a/node_modules/native-base/lib/commonjs/core/color-mode/hooks.js
+++ b/node_modules/native-base/lib/commonjs/core/color-mode/hooks.js
@@ -45,9 +45,9 @@ const useAppState = () => {
const subscription = _react.default.useMemo(() => ({
getCurrentValue: () => _reactNative.AppState.currentState,
subscribe: callback => {
- _reactNative.AppState.addEventListener('change', callback);
+ const sb = _reactNative.AppState.addEventListener('change', callback);
- return () => _reactNative.AppState.removeEventListener('change', callback);
+ return () => sb.remove()
}
}), []); After next release, just delete this patch. |
Any idea on witch version this fix will be introduced? Still getting this warning:
|
Getting the same error here when running tests with Jest `console.error
|
I'm using native-base version 3.4.19 and still have the issue! Any updates on this? |
Yes, got the same error, please fix it 🙏 Update: After updating to "native-base": "^3.4.25", jest no longer throws this error 👍 |
Hi
// The below implementation is taken from React Native's source and added a flag to conditionally attach/remove listeners
export const useDimensionsWithEnable = ({ enable }: { enable?: boolean }) => {
const [dimensions, setDimensions] = React.useState(() =>
Dimensions.get('window')
);
React.useEffect(() => {
if (enable) {
function handleChange({ window }: { window: ScaledSize }) {
if (
dimensions.width !== window.width ||
dimensions.height !== window.height ||
dimensions.scale !== window.scale ||
dimensions.fontScale !== window.fontScale
) {
setDimensions(window);
}
}
Dimensions.addEventListener('change', handleChange);
// We might have missed an update between calling `get` in render and
// `addEventListener` in this handler, so we set it here. If there was
// no change, React will filter out this update as a no-op.
handleChange({ window: Dimensions.get('window') });
return () => {
Dimensions.removeEventListener('change', handleChange); // <- HERE! ####################
};
}
return () => {};
}, [dimensions, enable]);
return dimensions;
}; |
Version
|
Same here but with the badge component, im doing the following: const TestComponent = (props: Record<string, unknown>) => <View {...props} />
jest.mock('native-base', () => ({
...jest.requireActual('native-base'),
HamburgerIcon: () => <TestComponent testID="menu-icon" />,
AddIcon: () => <TestComponent testID="add-icon" />,
})) the error: TypeError: Cannot read properties of undefined (reading 'Badge')
7 | const TestComponent = (props: Record<string, unknown>) => <View {...props} />
8 |
> 9 | jest.mock('native-base', () => ({
| ^
10 | ...jest.requireActual('native-base'),
11 | HamburgerIcon: () => <TestComponent testID="menu-icon" />,
12 | AddIcon: () => <TestComponent testID="add-icon" />,
at Object.get [as Badge] (node_modules/native-base/lib/commonjs/index.js:95:24)
at Function.assign (<anonymous>)
at assign (app/test/ui/pages/HomePage/components/Header.test.tsx:9:26)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/components/primitives/Hidden/HiddenSSR.tsx:2:1)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/components/primitives/Hidden/index.tsx:9:1)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/components/primitives/index.ts:69:1)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/components/composites/Alert/AlertIcon.tsx:2:1)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/components/composites/Alert/index.tsx:1:1)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/components/composites/index.ts:13:1)
at Object.<anonymous> (node_modules/native-base/lib/commonjs/index.tsx:1:1) |
Came across this and same issue as @joaosousafranco
|
This solved the last two issues for me, from https://stackoverflow.com/a/70174052:
jest.mock('the-module-to-mock', () => {
const actualModule = jest.requireActual('the-module-to-mock')
return new Proxy(actualModule, {
get: (target, property) => {
switch (property) {
// add cases for exports you want to mock
// 👇👇👇
case 'foo': {
return jest.fn() // add `mockImplementation` etc
}
case 'bar': {
return jest.fn()
}
// fallback to the original module
default: {
return target[property]
}
}
},
})
}) |
Description
There was a warning thrown as we ran test as following:
TypeError: _reactNative.AppState.removeEventListener is not a function
CodeSandbox/Snack link
https://codesandbox.io/s/codesandbox-sse-example-forked-izm8zv?file=/sample.test.jsx
Steps to reproduce
yarn test
command then you will the see the warningNativeBase Version
3.4.15
Platform
Other Platform
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: