diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index ac8dca64..d71cf014 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -72,6 +72,8 @@ function render( wrapper.setProps(_) return wait() }, + ...(store ? { store: vuexStore } : {}), + ...(routes ? { router } : {}), ...getQueriesForElement(wrapper.element.parentNode) } } diff --git a/tests/__tests__/vue-router.js b/tests/__tests__/vue-router.js index 2a5fa241..12cc8337 100644 --- a/tests/__tests__/vue-router.js +++ b/tests/__tests__/vue-router.js @@ -14,6 +14,13 @@ const routes = [ afterEach(cleanup) +test('router instance available', async () => { + const { queryByTestId, router } = render(App, { routes }) + expect(router.currentRoute.path).toBe('/') + await fireEvent.click(queryByTestId('about-link')) + expect(router.currentRoute.path).toBe('/about') +}) + test('full app rendering/navigating', async () => { // Notice how we pass a `routes` object to our render function. const { queryByTestId } = render(App, { routes }) diff --git a/tests/__tests__/vuex.js b/tests/__tests__/vuex.js index 635aac69..0cab79b9 100644 --- a/tests/__tests__/vuex.js +++ b/tests/__tests__/vuex.js @@ -53,3 +53,10 @@ test('can render with vuex with custom store', async () => { expect(console.error).toHaveBeenCalled() }) + +test('vuex store instance available to programmatically fire actions', () => { + const { store } = renderVuexTestComponent() + expect(store.state).toEqual({ count: 1 }) + store.dispatch('increment') + expect(store.state).toEqual({ count: 2 }) +})