Skip to content
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

[No QA] Fix: StoryBook via mocking the navigationContext #8365

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import HTMLEngineProvider from '../src/components/HTMLEngineProvider';
import OnyxProvider from '../src/components/OnyxProvider';
import {LocaleContextProvider} from '../src/components/withLocalize';
import ONYXKEYS from '../src/ONYXKEYS';
import MockNavigationProvider from '../__mocks__/MockNavigationProvider';

Onyx.init({
keys: ONYXKEYS,
Expand All @@ -18,6 +19,7 @@ const decorators = [
OnyxProvider,
LocaleContextProvider,
HTMLEngineProvider,
MockNavigationProvider,
]}
>
<Story />
Expand Down
24 changes: 24 additions & 0 deletions __mocks__/MockNavigationProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import {NavigationContext} from '@react-navigation/native';

const propTypes = {
/** Rendered child component */
children: PropTypes.node.isRequired,
};

const MockNavigationProvider = props => (
<NavigationContext.Provider
value={{
isFocused: () => true,
addListener: () => {},
removeListener: () => {},
}}
>
{props.children}
</NavigationContext.Provider>
);

MockNavigationProvider.propTypes = propTypes;

export default MockNavigationProvider;