Skip to content

Commit

Permalink
Merge pull request #8365 from parasharrajat/story-fix
Browse files Browse the repository at this point in the history
[No QA] Fix: StoryBook via mocking the navigationContext
  • Loading branch information
luacmartins authored Mar 30, 2022
2 parents df4ac03 + 65efd66 commit 37361b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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;

0 comments on commit 37361b3

Please sign in to comment.