Skip to content

Error not thrown inside computed property #1565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
solidevolution opened this issue Jun 3, 2020 · 4 comments
Closed

Error not thrown inside computed property #1565

solidevolution opened this issue Jun 3, 2020 · 4 comments
Labels

Comments

@solidevolution
Copy link

solidevolution commented Jun 3, 2020

Version

1.0.3

Reproduction link

https://codesandbox.io/s/naughty-hofstadter-qsycv?file=/src/components/HelloWorld.spec.js

Steps to reproduce

  1. Write a component with a computed property
  2. throws an error inside the computed property
  3. Try to test this error with "toThrowError"

What is expected?

Error in computed property would be thrown

What is actually happening?

Error in computed property wouldn't be thrown

@solidevolution solidevolution changed the title Error not thrown inside computed Error not thrown inside computed property Jun 3, 2020
@lmiller1990 lmiller1990 added the bug label Jun 5, 2020
@lmiller1990
Copy link
Member

This could be to do with the custom error handler. https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/error.js. Vue (or VTU) could be swallowing the error.

I have tried fixing this once before but no luck.

Related: #1503

@AtofStryker
Copy link
Contributor

I actually do not think this is an issue with VTU, but instead Jest. I noticed in your code sandbox that an async function was passed into expect. This unfortunately doesn't work quite like most would expect it to behave. This issue as well as this stack overflow post should provide clarity.

In short, this will work:

    try {
      const wrapper = shallowMount(HelloWorld, {
        propsData: {
          color: "not-in-map"
        }
      });
      await wrapper.vm.$nextTick();
    }catch(e){
      expect(e).toEqual(new Error(`Color not found: not-in-map`))
    }

As well as a few other methods discussed here

@lmiller1990
Copy link
Member

I think you might be correct.

Might close this one, I don't think we can fix this in VTU; the above post should be a good enough work-around.

@solidevolution
Copy link
Author

Works perfect, thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants