From 3754adbf2e60783b35c1726acd9a4bcf31bbc499 Mon Sep 17 00:00:00 2001 From: John Brennan Date: Sun, 7 Jul 2019 20:19:06 +0100 Subject: [PATCH] add router and store access via utils, with tests --- src/vue-testing-library.js | 2 ++ tests/__tests__/vue-router.js | 7 +++++++ tests/__tests__/vuex.js | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index 8250894f..b5a39cdb 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 e4509796..d9d427f4 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 2ecebcc6..133e351e 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 }) +})