TypeError: routingState.equals is not a function | Jest test case












0















This is my selector.js file:-



const makeSelectLocationState = () => {
let prevRoutingState;
let prevRoutingStateJS;

return (state) => {
const routingState = state.get('route'); // or state.route

if (!routingState.equals(prevRoutingState)) {
prevRoutingState = routingState;
prevRoutingStateJS = routingState.toJS();
}

return prevRoutingStateJS;
};
};


and the following test case I have written:-



it('makeSelectLocationState function testing', () => {
const selectLocationState = makeSelectLocationState();
const mockedState = fromJS({
route: '',
});
expect(selectLocationState(mockedState)).toEqual('');
});


While running the test case using jest I get the following error:-



TypeError: routingState.equals is not a function









share|improve this question



























    0















    This is my selector.js file:-



    const makeSelectLocationState = () => {
    let prevRoutingState;
    let prevRoutingStateJS;

    return (state) => {
    const routingState = state.get('route'); // or state.route

    if (!routingState.equals(prevRoutingState)) {
    prevRoutingState = routingState;
    prevRoutingStateJS = routingState.toJS();
    }

    return prevRoutingStateJS;
    };
    };


    and the following test case I have written:-



    it('makeSelectLocationState function testing', () => {
    const selectLocationState = makeSelectLocationState();
    const mockedState = fromJS({
    route: '',
    });
    expect(selectLocationState(mockedState)).toEqual('');
    });


    While running the test case using jest I get the following error:-



    TypeError: routingState.equals is not a function









    share|improve this question

























      0












      0








      0








      This is my selector.js file:-



      const makeSelectLocationState = () => {
      let prevRoutingState;
      let prevRoutingStateJS;

      return (state) => {
      const routingState = state.get('route'); // or state.route

      if (!routingState.equals(prevRoutingState)) {
      prevRoutingState = routingState;
      prevRoutingStateJS = routingState.toJS();
      }

      return prevRoutingStateJS;
      };
      };


      and the following test case I have written:-



      it('makeSelectLocationState function testing', () => {
      const selectLocationState = makeSelectLocationState();
      const mockedState = fromJS({
      route: '',
      });
      expect(selectLocationState(mockedState)).toEqual('');
      });


      While running the test case using jest I get the following error:-



      TypeError: routingState.equals is not a function









      share|improve this question














      This is my selector.js file:-



      const makeSelectLocationState = () => {
      let prevRoutingState;
      let prevRoutingStateJS;

      return (state) => {
      const routingState = state.get('route'); // or state.route

      if (!routingState.equals(prevRoutingState)) {
      prevRoutingState = routingState;
      prevRoutingStateJS = routingState.toJS();
      }

      return prevRoutingStateJS;
      };
      };


      and the following test case I have written:-



      it('makeSelectLocationState function testing', () => {
      const selectLocationState = makeSelectLocationState();
      const mockedState = fromJS({
      route: '',
      });
      expect(selectLocationState(mockedState)).toEqual('');
      });


      While running the test case using jest I get the following error:-



      TypeError: routingState.equals is not a function






      javascript reactjs react-redux jestjs enzyme






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 6:03









      ShwetankShwetank

      14129




      14129
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The problem is here:



          const routingState = state.get('route'); 


          Sense you didn't get the routingState,possible undefined, so you will get this above error message.So check the date of routingState.



          And in the test file, pass mockedState to selectLocationState



          selectLocationState(mockedState)


          However,makeSelectLocationState function didn't have property.Maybe change to this:



          const makeSelectLocationState = (state) => {}





          share|improve this answer
























          • TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

            – Shwetank
            Nov 13 '18 at 7:05













          • @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

            – Root
            Nov 13 '18 at 7:07











          • The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

            – Shwetank
            Nov 13 '18 at 7:22













          • @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

            – Root
            Nov 13 '18 at 7:56



















          0














          route: ''
          const routingState = state.get('route');


          It looks like route is a string (an empty string). Strings do not have an equals method, so routingState.equals() doesn't exist.



          Perhaps you could set mockedState.route to an object that has an equals function:



          const mockedState = fromJS({
          route: { equals: item => item === item },
          });





          share|improve this answer























            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%2f53274746%2ftypeerror-routingstate-equals-is-not-a-function-jest-test-case%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














            The problem is here:



            const routingState = state.get('route'); 


            Sense you didn't get the routingState,possible undefined, so you will get this above error message.So check the date of routingState.



            And in the test file, pass mockedState to selectLocationState



            selectLocationState(mockedState)


            However,makeSelectLocationState function didn't have property.Maybe change to this:



            const makeSelectLocationState = (state) => {}





            share|improve this answer
























            • TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

              – Shwetank
              Nov 13 '18 at 7:05













            • @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

              – Root
              Nov 13 '18 at 7:07











            • The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

              – Shwetank
              Nov 13 '18 at 7:22













            • @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

              – Root
              Nov 13 '18 at 7:56
















            1














            The problem is here:



            const routingState = state.get('route'); 


            Sense you didn't get the routingState,possible undefined, so you will get this above error message.So check the date of routingState.



            And in the test file, pass mockedState to selectLocationState



            selectLocationState(mockedState)


            However,makeSelectLocationState function didn't have property.Maybe change to this:



            const makeSelectLocationState = (state) => {}





            share|improve this answer
























            • TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

              – Shwetank
              Nov 13 '18 at 7:05













            • @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

              – Root
              Nov 13 '18 at 7:07











            • The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

              – Shwetank
              Nov 13 '18 at 7:22













            • @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

              – Root
              Nov 13 '18 at 7:56














            1












            1








            1







            The problem is here:



            const routingState = state.get('route'); 


            Sense you didn't get the routingState,possible undefined, so you will get this above error message.So check the date of routingState.



            And in the test file, pass mockedState to selectLocationState



            selectLocationState(mockedState)


            However,makeSelectLocationState function didn't have property.Maybe change to this:



            const makeSelectLocationState = (state) => {}





            share|improve this answer













            The problem is here:



            const routingState = state.get('route'); 


            Sense you didn't get the routingState,possible undefined, so you will get this above error message.So check the date of routingState.



            And in the test file, pass mockedState to selectLocationState



            selectLocationState(mockedState)


            However,makeSelectLocationState function didn't have property.Maybe change to this:



            const makeSelectLocationState = (state) => {}






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 '18 at 6:56









            RootRoot

            1,513128




            1,513128













            • TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

              – Shwetank
              Nov 13 '18 at 7:05













            • @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

              – Root
              Nov 13 '18 at 7:07











            • The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

              – Shwetank
              Nov 13 '18 at 7:22













            • @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

              – Root
              Nov 13 '18 at 7:56



















            • TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

              – Shwetank
              Nov 13 '18 at 7:05













            • @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

              – Root
              Nov 13 '18 at 7:07











            • The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

              – Shwetank
              Nov 13 '18 at 7:22













            • @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

              – Root
              Nov 13 '18 at 7:56

















            TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

            – Shwetank
            Nov 13 '18 at 7:05







            TypeError: Cannot read property 'equals' of undefined. After making the changes I get this above error. @root

            – Shwetank
            Nov 13 '18 at 7:05















            @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

            – Root
            Nov 13 '18 at 7:07





            @Shwetank please provide the output of console.log(routingState) in makeSelectLocationState.

            – Root
            Nov 13 '18 at 7:07













            The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

            – Shwetank
            Nov 13 '18 at 7:22







            The output of the console.log(routingState) is Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false} @root

            – Shwetank
            Nov 13 '18 at 7:22















            @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

            – Root
            Nov 13 '18 at 7:56





            @Shwetank while the type of routingState is Map,and Map actually don't have equals function.You can use this:routingState.toString() === prevRoutingState.toString() or use forEach to check every item of routingState.

            – Root
            Nov 13 '18 at 7:56













            0














            route: ''
            const routingState = state.get('route');


            It looks like route is a string (an empty string). Strings do not have an equals method, so routingState.equals() doesn't exist.



            Perhaps you could set mockedState.route to an object that has an equals function:



            const mockedState = fromJS({
            route: { equals: item => item === item },
            });





            share|improve this answer




























              0














              route: ''
              const routingState = state.get('route');


              It looks like route is a string (an empty string). Strings do not have an equals method, so routingState.equals() doesn't exist.



              Perhaps you could set mockedState.route to an object that has an equals function:



              const mockedState = fromJS({
              route: { equals: item => item === item },
              });





              share|improve this answer


























                0












                0








                0







                route: ''
                const routingState = state.get('route');


                It looks like route is a string (an empty string). Strings do not have an equals method, so routingState.equals() doesn't exist.



                Perhaps you could set mockedState.route to an object that has an equals function:



                const mockedState = fromJS({
                route: { equals: item => item === item },
                });





                share|improve this answer













                route: ''
                const routingState = state.get('route');


                It looks like route is a string (an empty string). Strings do not have an equals method, so routingState.equals() doesn't exist.



                Perhaps you could set mockedState.route to an object that has an equals function:



                const mockedState = fromJS({
                route: { equals: item => item === item },
                });






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 7:49









                stonestone

                4,5754059




                4,5754059






























                    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%2f53274746%2ftypeerror-routingstate-equals-is-not-a-function-jest-test-case%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

                    Coverage of Google Street View

                    Full-time equivalent

                    Surfing