React testing - How can I mock or inject data in the store to be provided as props to componentreact-router - pass props to handler componentCan you force a React component to rerender without calling setState?How to conditionally add attributes to React components?How to set component default props on React componentReact component initialize state from propsMocking Redux store when testing React components?React testing library: Test attribute / propreact-testing-library react test component updatereact-testing-library: Render prop - Expected mock function to have been last called with: [false] But it was not calledReact/Mobx: Integration Tests with Stores Injected into Child Components

Derivative is just speed of change?

Why are we moving in circles with a tandem kayak?

What clothes would flying-people wear?

A conjectural trigonometric identity

Applications of pure mathematics in operations research

How can you tell the version of Ubuntu on a system in a .sh (bash) script?

How did Biff return to 2015 from 1955 without a lightning strike?

Word for soundtrack music which is part of the action of the movie

Why does Latex make a small adjustment when I change section color

My employer is refusing to give me the pay that was advertised after an internal job move

Correct word for a little toy that always stands up?

What do the novel titles of The Expanse series refer to?

How to calculate points under the curve?

Why do we need a voltage divider when we get the same voltage at the output as the input?

Just how much information should you share with a former client?

Password management for kids - what's a good way to start?

Should students have access to past exams or an exam bank?

Move arrows along a contour

How to remove rebar passing through an inaccessible pipe

Applying for mortgage when living together but only one will be on the mortgage

How does the barbarian's bonus damage from Rage interact with two-weapon fighting?

What is the term for completing a climbing route uncleanly?

Adding a (stair/baby) gate without facing walls

Gold Battle KoTH



React testing - How can I mock or inject data in the store to be provided as props to component


react-router - pass props to handler componentCan you force a React component to rerender without calling setState?How to conditionally add attributes to React components?How to set component default props on React componentReact component initialize state from propsMocking Redux store when testing React components?React testing library: Test attribute / propreact-testing-library react test component updatereact-testing-library: Render prop - Expected mock function to have been last called with: [false] But it was not calledReact/Mobx: Integration Tests with Stores Injected into Child Components






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I'm using jest and react-testing-library to provide unit test coverage for my app.



I use this handy helper function Kent C. Dodds showed in one of his videos:



const renderWithRedux = ui => (
...render(<Provider store=store>ui</Provider>),
store,
);


I use when I am testing connected components.



I am running into an issue where in order to render a component I needed some data fetched to accuaratly resolve a test, or atleast inject mock data into the store. I am failing to do so



this is my test:



test('navbar accepts props', async () => 
/**
* Something I was testing
*/
const functionToTest = () => async dispatch =>
dispatch(fetchTickets());
;

functionToTest();
const isReady = true;
const mockData =
sessionInformation:
ticket: label: 'Total Tickets' ,
sessionDuration: sessionLabel: 'Session Duration', duration: 42 ,
equipment: type: 'Desktop', operatingSystem: 'Windows' ,
,
component: isReady ,
tickets:
ticketPayload: [

number: '1020312039',
shortDescription: 'Accessories',
status: 'Active',
createdOnEpoch: 1512322200000,
,
],
,
;

const data = renderWithRedux(<Navbar props=mockData />);
);


The component I am testing:



const NavBar = (
openTickets: label ,
sessionDuration: sessionLabel, duration ,
tickets: ticketPayload = [] ,
isReady,
) => (!isReady ? (
<Container>
<LogoContainer>
<Logo src=logo alt="logo" />
<Header>Service Desk</Header>
</LogoContainer>

<SessionInformation className="session">
<NavbarInfo className="session-info">
<p>
<FontAwesomeIcon icon="ticket-alt" className="ticketIcon" />
label
</p>
<p>`$ticketPayload.length tickets`</p>
</NavbarInfo>
<NavbarInfo last className="session-info">
<p>
<FontAwesomeIcon icon="clock" className="ticketIcon" />
sessionLabel
</p>
<p>`$duration minutes`</p>
</NavbarInfo>
hasTokens() && (
<Button type="submit" onClick=() => console.log('notes')>
Notepad
</Button>
)
</SessionInformation>
</Container>
) : (
<LoaderContainer>
<RingLoader size=100 />
</LoaderContainer>
));


I need to make length calculations with ticketPayload however the main store is taking priority. Since that information has not been fetched, ticketPayload's is 0. I want to be able to atleast mock the data to be passed but haven't had any luck using props, as the store takes precedence.



Hope anyone can beam a light of help or share some guidance. Thanks in Advance!










share|improve this question


























  • First thing to consider - the object you're passing to NavBar via props is not providing the props it needs. For example, NavBar expects that 'isReady' attribute but you are passing it as an attribute of another object, component = isReady

    – leosteffen
    Mar 26 at 22:49











  • :/ that doesn't really solve my issue at it seems that those props are not doing anything. Since Navbar is connected to the redux store, it receives by precedence the store's props, and these props are empty arrays until they are fetched. I need it to take the mock data for testing purposes. Hope that makes sense @leosteffen

    – aromanarguello
    Mar 26 at 22:56












  • I'm not the best person to help with redux specifics, but I'd have 1) the component tested in isolation rather than connected to redux and 2) have the fetchTickets() function tested on its own. This way you can make sure your individual parts work as they should until you find out if/how to test them together.

    – leosteffen
    Mar 26 at 23:04











  • That makes sense. I do have each tested separaretly. I test my actions with redux-mock-stor and reducers separately.. I guess I wanted to simulate and test an end to end experience with the component lol

    – aromanarguello
    Mar 26 at 23:06







  • 1





    I see, just make sure you don't end up testing redux :P

    – leosteffen
    Mar 26 at 23:09

















4















I'm using jest and react-testing-library to provide unit test coverage for my app.



I use this handy helper function Kent C. Dodds showed in one of his videos:



const renderWithRedux = ui => (
...render(<Provider store=store>ui</Provider>),
store,
);


I use when I am testing connected components.



I am running into an issue where in order to render a component I needed some data fetched to accuaratly resolve a test, or atleast inject mock data into the store. I am failing to do so



this is my test:



test('navbar accepts props', async () => 
/**
* Something I was testing
*/
const functionToTest = () => async dispatch =>
dispatch(fetchTickets());
;

functionToTest();
const isReady = true;
const mockData =
sessionInformation:
ticket: label: 'Total Tickets' ,
sessionDuration: sessionLabel: 'Session Duration', duration: 42 ,
equipment: type: 'Desktop', operatingSystem: 'Windows' ,
,
component: isReady ,
tickets:
ticketPayload: [

number: '1020312039',
shortDescription: 'Accessories',
status: 'Active',
createdOnEpoch: 1512322200000,
,
],
,
;

const data = renderWithRedux(<Navbar props=mockData />);
);


The component I am testing:



const NavBar = (
openTickets: label ,
sessionDuration: sessionLabel, duration ,
tickets: ticketPayload = [] ,
isReady,
) => (!isReady ? (
<Container>
<LogoContainer>
<Logo src=logo alt="logo" />
<Header>Service Desk</Header>
</LogoContainer>

<SessionInformation className="session">
<NavbarInfo className="session-info">
<p>
<FontAwesomeIcon icon="ticket-alt" className="ticketIcon" />
label
</p>
<p>`$ticketPayload.length tickets`</p>
</NavbarInfo>
<NavbarInfo last className="session-info">
<p>
<FontAwesomeIcon icon="clock" className="ticketIcon" />
sessionLabel
</p>
<p>`$duration minutes`</p>
</NavbarInfo>
hasTokens() && (
<Button type="submit" onClick=() => console.log('notes')>
Notepad
</Button>
)
</SessionInformation>
</Container>
) : (
<LoaderContainer>
<RingLoader size=100 />
</LoaderContainer>
));


I need to make length calculations with ticketPayload however the main store is taking priority. Since that information has not been fetched, ticketPayload's is 0. I want to be able to atleast mock the data to be passed but haven't had any luck using props, as the store takes precedence.



Hope anyone can beam a light of help or share some guidance. Thanks in Advance!










share|improve this question


























  • First thing to consider - the object you're passing to NavBar via props is not providing the props it needs. For example, NavBar expects that 'isReady' attribute but you are passing it as an attribute of another object, component = isReady

    – leosteffen
    Mar 26 at 22:49











  • :/ that doesn't really solve my issue at it seems that those props are not doing anything. Since Navbar is connected to the redux store, it receives by precedence the store's props, and these props are empty arrays until they are fetched. I need it to take the mock data for testing purposes. Hope that makes sense @leosteffen

    – aromanarguello
    Mar 26 at 22:56












  • I'm not the best person to help with redux specifics, but I'd have 1) the component tested in isolation rather than connected to redux and 2) have the fetchTickets() function tested on its own. This way you can make sure your individual parts work as they should until you find out if/how to test them together.

    – leosteffen
    Mar 26 at 23:04











  • That makes sense. I do have each tested separaretly. I test my actions with redux-mock-stor and reducers separately.. I guess I wanted to simulate and test an end to end experience with the component lol

    – aromanarguello
    Mar 26 at 23:06







  • 1





    I see, just make sure you don't end up testing redux :P

    – leosteffen
    Mar 26 at 23:09













4












4








4








I'm using jest and react-testing-library to provide unit test coverage for my app.



I use this handy helper function Kent C. Dodds showed in one of his videos:



const renderWithRedux = ui => (
...render(<Provider store=store>ui</Provider>),
store,
);


I use when I am testing connected components.



I am running into an issue where in order to render a component I needed some data fetched to accuaratly resolve a test, or atleast inject mock data into the store. I am failing to do so



this is my test:



test('navbar accepts props', async () => 
/**
* Something I was testing
*/
const functionToTest = () => async dispatch =>
dispatch(fetchTickets());
;

functionToTest();
const isReady = true;
const mockData =
sessionInformation:
ticket: label: 'Total Tickets' ,
sessionDuration: sessionLabel: 'Session Duration', duration: 42 ,
equipment: type: 'Desktop', operatingSystem: 'Windows' ,
,
component: isReady ,
tickets:
ticketPayload: [

number: '1020312039',
shortDescription: 'Accessories',
status: 'Active',
createdOnEpoch: 1512322200000,
,
],
,
;

const data = renderWithRedux(<Navbar props=mockData />);
);


The component I am testing:



const NavBar = (
openTickets: label ,
sessionDuration: sessionLabel, duration ,
tickets: ticketPayload = [] ,
isReady,
) => (!isReady ? (
<Container>
<LogoContainer>
<Logo src=logo alt="logo" />
<Header>Service Desk</Header>
</LogoContainer>

<SessionInformation className="session">
<NavbarInfo className="session-info">
<p>
<FontAwesomeIcon icon="ticket-alt" className="ticketIcon" />
label
</p>
<p>`$ticketPayload.length tickets`</p>
</NavbarInfo>
<NavbarInfo last className="session-info">
<p>
<FontAwesomeIcon icon="clock" className="ticketIcon" />
sessionLabel
</p>
<p>`$duration minutes`</p>
</NavbarInfo>
hasTokens() && (
<Button type="submit" onClick=() => console.log('notes')>
Notepad
</Button>
)
</SessionInformation>
</Container>
) : (
<LoaderContainer>
<RingLoader size=100 />
</LoaderContainer>
));


I need to make length calculations with ticketPayload however the main store is taking priority. Since that information has not been fetched, ticketPayload's is 0. I want to be able to atleast mock the data to be passed but haven't had any luck using props, as the store takes precedence.



Hope anyone can beam a light of help or share some guidance. Thanks in Advance!










share|improve this question
















I'm using jest and react-testing-library to provide unit test coverage for my app.



I use this handy helper function Kent C. Dodds showed in one of his videos:



const renderWithRedux = ui => (
...render(<Provider store=store>ui</Provider>),
store,
);


I use when I am testing connected components.



I am running into an issue where in order to render a component I needed some data fetched to accuaratly resolve a test, or atleast inject mock data into the store. I am failing to do so



this is my test:



test('navbar accepts props', async () => 
/**
* Something I was testing
*/
const functionToTest = () => async dispatch =>
dispatch(fetchTickets());
;

functionToTest();
const isReady = true;
const mockData =
sessionInformation:
ticket: label: 'Total Tickets' ,
sessionDuration: sessionLabel: 'Session Duration', duration: 42 ,
equipment: type: 'Desktop', operatingSystem: 'Windows' ,
,
component: isReady ,
tickets:
ticketPayload: [

number: '1020312039',
shortDescription: 'Accessories',
status: 'Active',
createdOnEpoch: 1512322200000,
,
],
,
;

const data = renderWithRedux(<Navbar props=mockData />);
);


The component I am testing:



const NavBar = (
openTickets: label ,
sessionDuration: sessionLabel, duration ,
tickets: ticketPayload = [] ,
isReady,
) => (!isReady ? (
<Container>
<LogoContainer>
<Logo src=logo alt="logo" />
<Header>Service Desk</Header>
</LogoContainer>

<SessionInformation className="session">
<NavbarInfo className="session-info">
<p>
<FontAwesomeIcon icon="ticket-alt" className="ticketIcon" />
label
</p>
<p>`$ticketPayload.length tickets`</p>
</NavbarInfo>
<NavbarInfo last className="session-info">
<p>
<FontAwesomeIcon icon="clock" className="ticketIcon" />
sessionLabel
</p>
<p>`$duration minutes`</p>
</NavbarInfo>
hasTokens() && (
<Button type="submit" onClick=() => console.log('notes')>
Notepad
</Button>
)
</SessionInformation>
</Container>
) : (
<LoaderContainer>
<RingLoader size=100 />
</LoaderContainer>
));


I need to make length calculations with ticketPayload however the main store is taking priority. Since that information has not been fetched, ticketPayload's is 0. I want to be able to atleast mock the data to be passed but haven't had any luck using props, as the store takes precedence.



Hope anyone can beam a light of help or share some guidance. Thanks in Advance!







javascript reactjs jestjs react-testing-library






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 1:23









skyboyer

5,9021 gold badge16 silver badges37 bronze badges




5,9021 gold badge16 silver badges37 bronze badges










asked Mar 26 at 22:35









aromanarguelloaromanarguello

759 bronze badges




759 bronze badges















  • First thing to consider - the object you're passing to NavBar via props is not providing the props it needs. For example, NavBar expects that 'isReady' attribute but you are passing it as an attribute of another object, component = isReady

    – leosteffen
    Mar 26 at 22:49











  • :/ that doesn't really solve my issue at it seems that those props are not doing anything. Since Navbar is connected to the redux store, it receives by precedence the store's props, and these props are empty arrays until they are fetched. I need it to take the mock data for testing purposes. Hope that makes sense @leosteffen

    – aromanarguello
    Mar 26 at 22:56












  • I'm not the best person to help with redux specifics, but I'd have 1) the component tested in isolation rather than connected to redux and 2) have the fetchTickets() function tested on its own. This way you can make sure your individual parts work as they should until you find out if/how to test them together.

    – leosteffen
    Mar 26 at 23:04











  • That makes sense. I do have each tested separaretly. I test my actions with redux-mock-stor and reducers separately.. I guess I wanted to simulate and test an end to end experience with the component lol

    – aromanarguello
    Mar 26 at 23:06







  • 1





    I see, just make sure you don't end up testing redux :P

    – leosteffen
    Mar 26 at 23:09

















  • First thing to consider - the object you're passing to NavBar via props is not providing the props it needs. For example, NavBar expects that 'isReady' attribute but you are passing it as an attribute of another object, component = isReady

    – leosteffen
    Mar 26 at 22:49











  • :/ that doesn't really solve my issue at it seems that those props are not doing anything. Since Navbar is connected to the redux store, it receives by precedence the store's props, and these props are empty arrays until they are fetched. I need it to take the mock data for testing purposes. Hope that makes sense @leosteffen

    – aromanarguello
    Mar 26 at 22:56












  • I'm not the best person to help with redux specifics, but I'd have 1) the component tested in isolation rather than connected to redux and 2) have the fetchTickets() function tested on its own. This way you can make sure your individual parts work as they should until you find out if/how to test them together.

    – leosteffen
    Mar 26 at 23:04











  • That makes sense. I do have each tested separaretly. I test my actions with redux-mock-stor and reducers separately.. I guess I wanted to simulate and test an end to end experience with the component lol

    – aromanarguello
    Mar 26 at 23:06







  • 1





    I see, just make sure you don't end up testing redux :P

    – leosteffen
    Mar 26 at 23:09
















First thing to consider - the object you're passing to NavBar via props is not providing the props it needs. For example, NavBar expects that 'isReady' attribute but you are passing it as an attribute of another object, component = isReady

– leosteffen
Mar 26 at 22:49





First thing to consider - the object you're passing to NavBar via props is not providing the props it needs. For example, NavBar expects that 'isReady' attribute but you are passing it as an attribute of another object, component = isReady

– leosteffen
Mar 26 at 22:49













:/ that doesn't really solve my issue at it seems that those props are not doing anything. Since Navbar is connected to the redux store, it receives by precedence the store's props, and these props are empty arrays until they are fetched. I need it to take the mock data for testing purposes. Hope that makes sense @leosteffen

– aromanarguello
Mar 26 at 22:56






:/ that doesn't really solve my issue at it seems that those props are not doing anything. Since Navbar is connected to the redux store, it receives by precedence the store's props, and these props are empty arrays until they are fetched. I need it to take the mock data for testing purposes. Hope that makes sense @leosteffen

– aromanarguello
Mar 26 at 22:56














I'm not the best person to help with redux specifics, but I'd have 1) the component tested in isolation rather than connected to redux and 2) have the fetchTickets() function tested on its own. This way you can make sure your individual parts work as they should until you find out if/how to test them together.

– leosteffen
Mar 26 at 23:04





I'm not the best person to help with redux specifics, but I'd have 1) the component tested in isolation rather than connected to redux and 2) have the fetchTickets() function tested on its own. This way you can make sure your individual parts work as they should until you find out if/how to test them together.

– leosteffen
Mar 26 at 23:04













That makes sense. I do have each tested separaretly. I test my actions with redux-mock-stor and reducers separately.. I guess I wanted to simulate and test an end to end experience with the component lol

– aromanarguello
Mar 26 at 23:06






That makes sense. I do have each tested separaretly. I test my actions with redux-mock-stor and reducers separately.. I guess I wanted to simulate and test an end to end experience with the component lol

– aromanarguello
Mar 26 at 23:06





1




1





I see, just make sure you don't end up testing redux :P

– leosteffen
Mar 26 at 23:09





I see, just make sure you don't end up testing redux :P

– leosteffen
Mar 26 at 23:09












2 Answers
2






active

oldest

votes


















1














I created a helper function to wrap my components with redux.



import Provider from 'react-redux';
import configureMockStore from 'redux-mock-store';
import initialState from '../store/initialState';

const mockStore = (state = initialState) => configureMockStore()(state);

export const testableComponent = (component, state) =>
(<Provider store=mockStore(state)>component</Provider>);


And then you can call it just like this, passing your state



testableComponent(<YourComponent />, yourUpdatedMockedState)





share|improve this answer
































    1














    The official Writing Tests doc from Redux recommends this approach:




    But sometimes you want to test just the rendering of the component, without a Redux store.



    In order to be able to test the...component itself without having to deal with the decorator, we recommend you to also export the undecorated component




    In other words...export NavBar as a named export so you can access it in your tests.



    Then you can test it directly as a simple UI component that just renders based on the props you give it.






    share|improve this answer




















    • 1





      That makes complete sense as well! Thanks for sharing :)

      – aromanarguello
      Mar 27 at 1:44













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367150%2freact-testing-how-can-i-mock-or-inject-data-in-the-store-to-be-provided-as-pro%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I created a helper function to wrap my components with redux.



    import Provider from 'react-redux';
    import configureMockStore from 'redux-mock-store';
    import initialState from '../store/initialState';

    const mockStore = (state = initialState) => configureMockStore()(state);

    export const testableComponent = (component, state) =>
    (<Provider store=mockStore(state)>component</Provider>);


    And then you can call it just like this, passing your state



    testableComponent(<YourComponent />, yourUpdatedMockedState)





    share|improve this answer





























      1














      I created a helper function to wrap my components with redux.



      import Provider from 'react-redux';
      import configureMockStore from 'redux-mock-store';
      import initialState from '../store/initialState';

      const mockStore = (state = initialState) => configureMockStore()(state);

      export const testableComponent = (component, state) =>
      (<Provider store=mockStore(state)>component</Provider>);


      And then you can call it just like this, passing your state



      testableComponent(<YourComponent />, yourUpdatedMockedState)





      share|improve this answer



























        1












        1








        1







        I created a helper function to wrap my components with redux.



        import Provider from 'react-redux';
        import configureMockStore from 'redux-mock-store';
        import initialState from '../store/initialState';

        const mockStore = (state = initialState) => configureMockStore()(state);

        export const testableComponent = (component, state) =>
        (<Provider store=mockStore(state)>component</Provider>);


        And then you can call it just like this, passing your state



        testableComponent(<YourComponent />, yourUpdatedMockedState)





        share|improve this answer













        I created a helper function to wrap my components with redux.



        import Provider from 'react-redux';
        import configureMockStore from 'redux-mock-store';
        import initialState from '../store/initialState';

        const mockStore = (state = initialState) => configureMockStore()(state);

        export const testableComponent = (component, state) =>
        (<Provider store=mockStore(state)>component</Provider>);


        And then you can call it just like this, passing your state



        testableComponent(<YourComponent />, yourUpdatedMockedState)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 23:31









        Alexandr ZavaliiAlexandr Zavalii

        1,0609 silver badges25 bronze badges




        1,0609 silver badges25 bronze badges


























            1














            The official Writing Tests doc from Redux recommends this approach:




            But sometimes you want to test just the rendering of the component, without a Redux store.



            In order to be able to test the...component itself without having to deal with the decorator, we recommend you to also export the undecorated component




            In other words...export NavBar as a named export so you can access it in your tests.



            Then you can test it directly as a simple UI component that just renders based on the props you give it.






            share|improve this answer




















            • 1





              That makes complete sense as well! Thanks for sharing :)

              – aromanarguello
              Mar 27 at 1:44















            1














            The official Writing Tests doc from Redux recommends this approach:




            But sometimes you want to test just the rendering of the component, without a Redux store.



            In order to be able to test the...component itself without having to deal with the decorator, we recommend you to also export the undecorated component




            In other words...export NavBar as a named export so you can access it in your tests.



            Then you can test it directly as a simple UI component that just renders based on the props you give it.






            share|improve this answer




















            • 1





              That makes complete sense as well! Thanks for sharing :)

              – aromanarguello
              Mar 27 at 1:44













            1












            1








            1







            The official Writing Tests doc from Redux recommends this approach:




            But sometimes you want to test just the rendering of the component, without a Redux store.



            In order to be able to test the...component itself without having to deal with the decorator, we recommend you to also export the undecorated component




            In other words...export NavBar as a named export so you can access it in your tests.



            Then you can test it directly as a simple UI component that just renders based on the props you give it.






            share|improve this answer













            The official Writing Tests doc from Redux recommends this approach:




            But sometimes you want to test just the rendering of the component, without a Redux store.



            In order to be able to test the...component itself without having to deal with the decorator, we recommend you to also export the undecorated component




            In other words...export NavBar as a named export so you can access it in your tests.



            Then you can test it directly as a simple UI component that just renders based on the props you give it.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 27 at 1:43









            brian-lives-outdoorsbrian-lives-outdoors

            14.9k1 gold badge16 silver badges40 bronze badges




            14.9k1 gold badge16 silver badges40 bronze badges










            • 1





              That makes complete sense as well! Thanks for sharing :)

              – aromanarguello
              Mar 27 at 1:44












            • 1





              That makes complete sense as well! Thanks for sharing :)

              – aromanarguello
              Mar 27 at 1:44







            1




            1





            That makes complete sense as well! Thanks for sharing :)

            – aromanarguello
            Mar 27 at 1:44





            That makes complete sense as well! Thanks for sharing :)

            – aromanarguello
            Mar 27 at 1:44

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367150%2freact-testing-how-can-i-mock-or-inject-data-in-the-store-to-be-provided-as-pro%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현