SecurityError: replaceState cannot update history to a URL which differs in components other than in path,...












1














I am trying to test a react component using jest and enzyme. But whenever i try to mount the component, i am getting following error.



Error: Uncaught [SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.]
at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:17458:7)
at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:18912:3) SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.
at HistoryImpl._sharedPushAndReplaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:83:15)
at HistoryImpl.replaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:57:10)
at History.replaceState (node_modules/jsdom/lib/jsdom/living/generated/History.js:129:21)
at node_modules/history/createBrowserHistory.js:211:23
at Object.confirmTransitionTo (node_modules/history/createTransitionManager.js:44:7)
at Object.replace (node_modules/history/createBrowserHistory.js:202:23)
at Redirect.perform (node_modules/react-router/Redirect.js:102:15)
at Redirect.componentDidMount (node_modules/react-router/Redirect.js:61:32)
at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15961:22)
at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:17262:7)
console.error node_modules/react-dom/cjs/react-dom.development.js:15749
The above error occurred in the <Redirect> component:
in Redirect (created by ProfileContainer)
in ProfileContainer
in Router (created by BrowserRouter)
in BrowserRouter (created by WrapperComponent)
in WrapperComponent


This is my react component






export class ProfileContainer extends Component {
render() {
if (this.props.loginInfo.loginStatus !== "LOGIN_SUCCESS") {
return <Redirect to={"/" + getOrgName() + "/home"} />;
}

const userData = this.props.userData.results[0];
return <Profile userData={userData} loginInfo={this.props.loginInfo} />;
}
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>





This is my test file




describe("<ProfileContainer />", () => {
it("renders without crashing", () => {
const wrapper = mount(
<BrowserRouter>
<ProfileContainer {...mockProps} />
</BrowserRouter>
);
});
});





Configuration



jest: 23.6.0
enzyme: 3.7.0
enzyme-adapter-react-16: 1.7.0


any suggestions will be helpful.










share|improve this question





























    1














    I am trying to test a react component using jest and enzyme. But whenever i try to mount the component, i am getting following error.



    Error: Uncaught [SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.]
    at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
    at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
    at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
    at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
    at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
    at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
    at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
    at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
    at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:17458:7)
    at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:18912:3) SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.
    at HistoryImpl._sharedPushAndReplaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:83:15)
    at HistoryImpl.replaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:57:10)
    at History.replaceState (node_modules/jsdom/lib/jsdom/living/generated/History.js:129:21)
    at node_modules/history/createBrowserHistory.js:211:23
    at Object.confirmTransitionTo (node_modules/history/createTransitionManager.js:44:7)
    at Object.replace (node_modules/history/createBrowserHistory.js:202:23)
    at Redirect.perform (node_modules/react-router/Redirect.js:102:15)
    at Redirect.componentDidMount (node_modules/react-router/Redirect.js:61:32)
    at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15961:22)
    at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:17262:7)
    console.error node_modules/react-dom/cjs/react-dom.development.js:15749
    The above error occurred in the <Redirect> component:
    in Redirect (created by ProfileContainer)
    in ProfileContainer
    in Router (created by BrowserRouter)
    in BrowserRouter (created by WrapperComponent)
    in WrapperComponent


    This is my react component






    export class ProfileContainer extends Component {
    render() {
    if (this.props.loginInfo.loginStatus !== "LOGIN_SUCCESS") {
    return <Redirect to={"/" + getOrgName() + "/home"} />;
    }

    const userData = this.props.userData.results[0];
    return <Profile userData={userData} loginInfo={this.props.loginInfo} />;
    }
    }

    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>





    This is my test file




    describe("<ProfileContainer />", () => {
    it("renders without crashing", () => {
    const wrapper = mount(
    <BrowserRouter>
    <ProfileContainer {...mockProps} />
    </BrowserRouter>
    );
    });
    });





    Configuration



    jest: 23.6.0
    enzyme: 3.7.0
    enzyme-adapter-react-16: 1.7.0


    any suggestions will be helpful.










    share|improve this question



























      1












      1








      1







      I am trying to test a react component using jest and enzyme. But whenever i try to mount the component, i am getting following error.



      Error: Uncaught [SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.]
      at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
      at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:17458:7)
      at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:18912:3) SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.
      at HistoryImpl._sharedPushAndReplaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:83:15)
      at HistoryImpl.replaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:57:10)
      at History.replaceState (node_modules/jsdom/lib/jsdom/living/generated/History.js:129:21)
      at node_modules/history/createBrowserHistory.js:211:23
      at Object.confirmTransitionTo (node_modules/history/createTransitionManager.js:44:7)
      at Object.replace (node_modules/history/createBrowserHistory.js:202:23)
      at Redirect.perform (node_modules/react-router/Redirect.js:102:15)
      at Redirect.componentDidMount (node_modules/react-router/Redirect.js:61:32)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15961:22)
      at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:17262:7)
      console.error node_modules/react-dom/cjs/react-dom.development.js:15749
      The above error occurred in the <Redirect> component:
      in Redirect (created by ProfileContainer)
      in ProfileContainer
      in Router (created by BrowserRouter)
      in BrowserRouter (created by WrapperComponent)
      in WrapperComponent


      This is my react component






      export class ProfileContainer extends Component {
      render() {
      if (this.props.loginInfo.loginStatus !== "LOGIN_SUCCESS") {
      return <Redirect to={"/" + getOrgName() + "/home"} />;
      }

      const userData = this.props.userData.results[0];
      return <Profile userData={userData} loginInfo={this.props.loginInfo} />;
      }
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>





      This is my test file




      describe("<ProfileContainer />", () => {
      it("renders without crashing", () => {
      const wrapper = mount(
      <BrowserRouter>
      <ProfileContainer {...mockProps} />
      </BrowserRouter>
      );
      });
      });





      Configuration



      jest: 23.6.0
      enzyme: 3.7.0
      enzyme-adapter-react-16: 1.7.0


      any suggestions will be helpful.










      share|improve this question















      I am trying to test a react component using jest and enzyme. But whenever i try to mount the component, i am getting following error.



      Error: Uncaught [SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.]
      at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
      at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:17458:7)
      at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:18912:3) SecurityError: replaceState cannot update history to a URL which differs in components other than in path, query, or fragment.
      at HistoryImpl._sharedPushAndReplaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:83:15)
      at HistoryImpl.replaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:57:10)
      at History.replaceState (node_modules/jsdom/lib/jsdom/living/generated/History.js:129:21)
      at node_modules/history/createBrowserHistory.js:211:23
      at Object.confirmTransitionTo (node_modules/history/createTransitionManager.js:44:7)
      at Object.replace (node_modules/history/createBrowserHistory.js:202:23)
      at Redirect.perform (node_modules/react-router/Redirect.js:102:15)
      at Redirect.componentDidMount (node_modules/react-router/Redirect.js:61:32)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:15961:22)
      at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:17262:7)
      console.error node_modules/react-dom/cjs/react-dom.development.js:15749
      The above error occurred in the <Redirect> component:
      in Redirect (created by ProfileContainer)
      in ProfileContainer
      in Router (created by BrowserRouter)
      in BrowserRouter (created by WrapperComponent)
      in WrapperComponent


      This is my react component






      export class ProfileContainer extends Component {
      render() {
      if (this.props.loginInfo.loginStatus !== "LOGIN_SUCCESS") {
      return <Redirect to={"/" + getOrgName() + "/home"} />;
      }

      const userData = this.props.userData.results[0];
      return <Profile userData={userData} loginInfo={this.props.loginInfo} />;
      }
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>





      This is my test file




      describe("<ProfileContainer />", () => {
      it("renders without crashing", () => {
      const wrapper = mount(
      <BrowserRouter>
      <ProfileContainer {...mockProps} />
      </BrowserRouter>
      );
      });
      });





      Configuration



      jest: 23.6.0
      enzyme: 3.7.0
      enzyme-adapter-react-16: 1.7.0


      any suggestions will be helpful.






      export class ProfileContainer extends Component {
      render() {
      if (this.props.loginInfo.loginStatus !== "LOGIN_SUCCESS") {
      return <Redirect to={"/" + getOrgName() + "/home"} />;
      }

      const userData = this.props.userData.results[0];
      return <Profile userData={userData} loginInfo={this.props.loginInfo} />;
      }
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>





      export class ProfileContainer extends Component {
      render() {
      if (this.props.loginInfo.loginStatus !== "LOGIN_SUCCESS") {
      return <Redirect to={"/" + getOrgName() + "/home"} />;
      }

      const userData = this.props.userData.results[0];
      return <Profile userData={userData} loginInfo={this.props.loginInfo} />;
      }
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>





      describe("<ProfileContainer />", () => {
      it("renders without crashing", () => {
      const wrapper = mount(
      <BrowserRouter>
      <ProfileContainer {...mockProps} />
      </BrowserRouter>
      );
      });
      });





      describe("<ProfileContainer />", () => {
      it("renders without crashing", () => {
      const wrapper = mount(
      <BrowserRouter>
      <ProfileContainer {...mockProps} />
      </BrowserRouter>
      );
      });
      });






      reactjs react-router jestjs enzyme






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 16:10









      skyboyer

      3,29611128




      3,29611128










      asked Nov 21 at 9:28









      Akashdeep Samantra

      83




      83





























          active

          oldest

          votes











          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%2f53408895%2fsecurityerror-replacestate-cannot-update-history-to-a-url-which-differs-in-comp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53408895%2fsecurityerror-replacestate-cannot-update-history-to-a-url-which-differs-in-comp%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

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'