Skip to content

Change mocks mid-test #2097

Open
Open
@steven-twerdochlib

Description

@steven-twerdochlib

Hi,
I would like to change a mock in my wrapper without having to recreate a whole new wrapper, is this possible?
Here's my wrapper:

  let wrapper;
  let store;
  let state;
  let getters;
  let $route = {
    meta: {
      app: 'testMeta1'
    }
  };
  const $router = {
    go: vi.fn()
  };
  state = {
    };
    getters = {
      }
    };
    const actions = {
    };
    store = createStore({
      getters,
      actions,
      state,
      mutations: {
        }
      }
    });

    wrapper = shallowMount(ImageViewer, {
      global: {
        plugins: [store],
        mocks: {
          $route,
          $router
        }
      }
    });

So what I would like to do is change the $route.meta.app for a specific test, to the below without having to create a whole new wrapper.

let $route = {
  meta: {
    app: 'testMeta2'
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions