Skip to content

In MountingOptions is missing computed property #545

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
mariosh346 opened this issue Apr 21, 2021 · 4 comments
Closed

In MountingOptions is missing computed property #545

mariosh346 opened this issue Apr 21, 2021 · 4 comments

Comments

@mariosh346
Copy link

mariosh346 commented Apr 21, 2021

In vue-test-utils v.1.1.2 there was a computed option in MountingOptions. Is this removed?
Is there a way to mock computed properties?

@afontcu
Copy link
Member

afontcu commented Apr 21, 2021

Hi! 👋 I might be wrong, but I'm not entirely sure VTU 1 provides a computed option 🤔 Could you share a use case where mocking a computed property is necessary? I'd say a sensible approach would be to pass down the right props / interact with the component until the computed has the right value.

@mariosh346
Copy link
Author

The most times that this is needed is to mock a complex computed and test it separately.
vuejs/vue-test-utils#331 Here you can see that they propose the use of computed option instead of setComputed

@lmiller1990
Copy link
Member

lmiller1990 commented Apr 26, 2021

We have a computed mounting option a looooong time ago, not in 1.1.2, though. It was removed for the same reason methods was removed (see the discussion in the thread you linked - it can lead to weird edge cases and false positives).

Since computed properties are just derived from other sources (like data and props) you can generally use the data and props mounting option to accomplish the same thing.

If you want additional guidance, please post an example of the test you'd like to write. computed as a mounting option was deprecated a long time ago in v1 - the goal of v2 is to match VTU v1's API, so we won't add additional features here that are not supported in v1 at this point in time.

@doutatsu
Copy link

This is quite a shame this was removed. Mocking computed properties made it a lot easier to use a real VueX store, but the stubbing out a specific getter for example, for a specific test:

      beforeEach(() => {
        store = createStore({
          modules: {
            lists: {
              namespaced: true,
              state: lists.state,
              mutations: lists.mutations,
              getters: lists.getters,
            },
          },
        });

        actions = shallowMount(TheDashboardListActions, {
          computed: { selectionModeActive: () => true },
          global: {
            plugins: [store],
            mocks: {
              $grid: { lg: false },
              $screen: { touch: true },
            },
          },
        });
      });

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

No branches or pull requests

4 participants