Why does an expectation in $nextTick never fail?












3














I need to use $nextTick in order to test some parts of my program. Somehow, it breaks my tests and make them success all the time - even when they should fail.



A minimal test sample would look like this:



import App from "./App";
import { shallowMount } from "@vue/test-utils";

it("should fail", () => {
const wrapper = shallowMount(App);
wrapper.vm.$nextTick(() => {
expect(1).toBe(3);
done();
});
});


You can find a sandbox example here



If you open the console, you should find the following error messages:



[Vue warn]: Error in nextTick: "Error: expect(received).toBe(expected)
Error: expect(received).toBe(expected)


Why does the test success? Why are the errors ignored? How do I use $nextTick properly if note like so?










share|improve this question



























    3














    I need to use $nextTick in order to test some parts of my program. Somehow, it breaks my tests and make them success all the time - even when they should fail.



    A minimal test sample would look like this:



    import App from "./App";
    import { shallowMount } from "@vue/test-utils";

    it("should fail", () => {
    const wrapper = shallowMount(App);
    wrapper.vm.$nextTick(() => {
    expect(1).toBe(3);
    done();
    });
    });


    You can find a sandbox example here



    If you open the console, you should find the following error messages:



    [Vue warn]: Error in nextTick: "Error: expect(received).toBe(expected)
    Error: expect(received).toBe(expected)


    Why does the test success? Why are the errors ignored? How do I use $nextTick properly if note like so?










    share|improve this question

























      3












      3








      3







      I need to use $nextTick in order to test some parts of my program. Somehow, it breaks my tests and make them success all the time - even when they should fail.



      A minimal test sample would look like this:



      import App from "./App";
      import { shallowMount } from "@vue/test-utils";

      it("should fail", () => {
      const wrapper = shallowMount(App);
      wrapper.vm.$nextTick(() => {
      expect(1).toBe(3);
      done();
      });
      });


      You can find a sandbox example here



      If you open the console, you should find the following error messages:



      [Vue warn]: Error in nextTick: "Error: expect(received).toBe(expected)
      Error: expect(received).toBe(expected)


      Why does the test success? Why are the errors ignored? How do I use $nextTick properly if note like so?










      share|improve this question













      I need to use $nextTick in order to test some parts of my program. Somehow, it breaks my tests and make them success all the time - even when they should fail.



      A minimal test sample would look like this:



      import App from "./App";
      import { shallowMount } from "@vue/test-utils";

      it("should fail", () => {
      const wrapper = shallowMount(App);
      wrapper.vm.$nextTick(() => {
      expect(1).toBe(3);
      done();
      });
      });


      You can find a sandbox example here



      If you open the console, you should find the following error messages:



      [Vue warn]: Error in nextTick: "Error: expect(received).toBe(expected)
      Error: expect(received).toBe(expected)


      Why does the test success? Why are the errors ignored? How do I use $nextTick properly if note like so?







      vue.js jestjs vue-test-utils






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      papillon

      11411




      11411
























          2 Answers
          2






          active

          oldest

          votes


















          1















          In order to wait until Vue.js has finished updating the DOM after a
          data change, you can use Vue.nextTick(callback) immediately after the
          data is changed. The callback will be called after the DOM has been
          updated.




          I can not see any trigger that change DOM in your test. And you missed done argument in test callback



          For example in the following this is wrapper.find('button').trigger('click')



          it('fetches async when a button is clicked', (done) => {
          const wrapper = shallowMount(Foo)
          wrapper.find('button').trigger('click')
          wrapper.vm.$nextTick(() => {
          expect(wrapper.vm.value).toBe('value')
          done()
          })
          })





          share|improve this answer





























            1














            You need to pass in done as an argument to your test (and also need to set Vue.config.errorHandler)



            it("should fail", (done) => {
            Vue.config.errorHandler = done;
            const wrapper = shallowMount(App);
            wrapper.vm.$nextTick(() => {
            expect(1).toBe(3);
            done();
            });
            });


            Or you can use the promise version of nextTick, in this case you don't need the done function:



            it("should fail", () => {
            const wrapper = shallowMount(App);
            return wrapper.vm.$nextTick().then(() => {
            expect(1).toBe(3);
            });
            });


            See also in the guides: https://vue-test-utils.vuejs.org/guides/#what-about-nexttick






            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%2f53944447%2fwhy-does-an-expectation-in-nexttick-never-fail%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















              In order to wait until Vue.js has finished updating the DOM after a
              data change, you can use Vue.nextTick(callback) immediately after the
              data is changed. The callback will be called after the DOM has been
              updated.




              I can not see any trigger that change DOM in your test. And you missed done argument in test callback



              For example in the following this is wrapper.find('button').trigger('click')



              it('fetches async when a button is clicked', (done) => {
              const wrapper = shallowMount(Foo)
              wrapper.find('button').trigger('click')
              wrapper.vm.$nextTick(() => {
              expect(wrapper.vm.value).toBe('value')
              done()
              })
              })





              share|improve this answer


























                1















                In order to wait until Vue.js has finished updating the DOM after a
                data change, you can use Vue.nextTick(callback) immediately after the
                data is changed. The callback will be called after the DOM has been
                updated.




                I can not see any trigger that change DOM in your test. And you missed done argument in test callback



                For example in the following this is wrapper.find('button').trigger('click')



                it('fetches async when a button is clicked', (done) => {
                const wrapper = shallowMount(Foo)
                wrapper.find('button').trigger('click')
                wrapper.vm.$nextTick(() => {
                expect(wrapper.vm.value).toBe('value')
                done()
                })
                })





                share|improve this answer
























                  1












                  1








                  1







                  In order to wait until Vue.js has finished updating the DOM after a
                  data change, you can use Vue.nextTick(callback) immediately after the
                  data is changed. The callback will be called after the DOM has been
                  updated.




                  I can not see any trigger that change DOM in your test. And you missed done argument in test callback



                  For example in the following this is wrapper.find('button').trigger('click')



                  it('fetches async when a button is clicked', (done) => {
                  const wrapper = shallowMount(Foo)
                  wrapper.find('button').trigger('click')
                  wrapper.vm.$nextTick(() => {
                  expect(wrapper.vm.value).toBe('value')
                  done()
                  })
                  })





                  share|improve this answer













                  In order to wait until Vue.js has finished updating the DOM after a
                  data change, you can use Vue.nextTick(callback) immediately after the
                  data is changed. The callback will be called after the DOM has been
                  updated.




                  I can not see any trigger that change DOM in your test. And you missed done argument in test callback



                  For example in the following this is wrapper.find('button').trigger('click')



                  it('fetches async when a button is clicked', (done) => {
                  const wrapper = shallowMount(Foo)
                  wrapper.find('button').trigger('click')
                  wrapper.vm.$nextTick(() => {
                  expect(wrapper.vm.value).toBe('value')
                  done()
                  })
                  })






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Maxim Shubin

                  91110




                  91110

























                      1














                      You need to pass in done as an argument to your test (and also need to set Vue.config.errorHandler)



                      it("should fail", (done) => {
                      Vue.config.errorHandler = done;
                      const wrapper = shallowMount(App);
                      wrapper.vm.$nextTick(() => {
                      expect(1).toBe(3);
                      done();
                      });
                      });


                      Or you can use the promise version of nextTick, in this case you don't need the done function:



                      it("should fail", () => {
                      const wrapper = shallowMount(App);
                      return wrapper.vm.$nextTick().then(() => {
                      expect(1).toBe(3);
                      });
                      });


                      See also in the guides: https://vue-test-utils.vuejs.org/guides/#what-about-nexttick






                      share|improve this answer


























                        1














                        You need to pass in done as an argument to your test (and also need to set Vue.config.errorHandler)



                        it("should fail", (done) => {
                        Vue.config.errorHandler = done;
                        const wrapper = shallowMount(App);
                        wrapper.vm.$nextTick(() => {
                        expect(1).toBe(3);
                        done();
                        });
                        });


                        Or you can use the promise version of nextTick, in this case you don't need the done function:



                        it("should fail", () => {
                        const wrapper = shallowMount(App);
                        return wrapper.vm.$nextTick().then(() => {
                        expect(1).toBe(3);
                        });
                        });


                        See also in the guides: https://vue-test-utils.vuejs.org/guides/#what-about-nexttick






                        share|improve this answer
























                          1












                          1








                          1






                          You need to pass in done as an argument to your test (and also need to set Vue.config.errorHandler)



                          it("should fail", (done) => {
                          Vue.config.errorHandler = done;
                          const wrapper = shallowMount(App);
                          wrapper.vm.$nextTick(() => {
                          expect(1).toBe(3);
                          done();
                          });
                          });


                          Or you can use the promise version of nextTick, in this case you don't need the done function:



                          it("should fail", () => {
                          const wrapper = shallowMount(App);
                          return wrapper.vm.$nextTick().then(() => {
                          expect(1).toBe(3);
                          });
                          });


                          See also in the guides: https://vue-test-utils.vuejs.org/guides/#what-about-nexttick






                          share|improve this answer












                          You need to pass in done as an argument to your test (and also need to set Vue.config.errorHandler)



                          it("should fail", (done) => {
                          Vue.config.errorHandler = done;
                          const wrapper = shallowMount(App);
                          wrapper.vm.$nextTick(() => {
                          expect(1).toBe(3);
                          done();
                          });
                          });


                          Or you can use the promise version of nextTick, in this case you don't need the done function:



                          it("should fail", () => {
                          const wrapper = shallowMount(App);
                          return wrapper.vm.$nextTick().then(() => {
                          expect(1).toBe(3);
                          });
                          });


                          See also in the guides: https://vue-test-utils.vuejs.org/guides/#what-about-nexttick







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          nemesv

                          122k12340321




                          122k12340321






























                              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%2f53944447%2fwhy-does-an-expectation-in-nexttick-never-fail%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

                              Monofisismo

                              Angular Downloading a file using contenturl with Basic Authentication

                              Olmecas