From fc20722b919ded41a883e5893e5f46f6e375d167 Mon Sep 17 00:00:00 2001 From: Tim Maguire Date: Thu, 27 Dec 2018 08:49:12 +0000 Subject: [PATCH] Enables child component stubs --- README.md | 1 + src/index.js | 4 +++- tests/__tests__/Integration-with-stub.js | 11 +++++++++++ tests/__tests__/components/Form.vue | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/__tests__/Integration-with-stub.js create mode 100644 tests/__tests__/components/Form.vue diff --git a/README.md b/README.md index f89b5a0c..683d0465 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ The `render` function takes up to 3 parameters and returns an object with some h * props - The component props to be passed to TestComponent * store - The object definition of a Vuex store, if present `render` will configure a Vuex store and pass to mount. * routes - A set of routes, if present render will configure VueRouter and pass to mount. +* stubs - [An Array of component names to stub, or an object.](https://vue-test-utils.vuejs.org/api/options.html#stubs) 3. configurationCb - A callback to be called passing the Vue instance when created. This allows 3rd party plugins to be installed prior to mount. ### fireEvent diff --git a/src/index.js b/src/index.js index 7782dc2f..fe268a4f 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,8 @@ const mountedWrappers = new Set() function render (TestComponent, { props = null, store = null, - routes = null + routes = null, + stubs = [], } = {}, configurationCb) { const localVue = createLocalVue() let vuexStore = null @@ -43,6 +44,7 @@ function render (TestComponent, { localVue, router, store: vuexStore, + stubs, propsData: { ...props }, attachToDocument: true, sync: false diff --git a/tests/__tests__/Integration-with-stub.js b/tests/__tests__/Integration-with-stub.js new file mode 100644 index 00000000..5665fce3 --- /dev/null +++ b/tests/__tests__/Integration-with-stub.js @@ -0,0 +1,11 @@ +import { render, cleanup, fireEvent } from "../../src" +import Form from "./components/Form" + +afterEach(cleanup) + +test("Form contians with search button", () => { + const { getByText } = render(Form, { + stubs: ['font-awesome-icon'] + }) + getByText("Search now") +}) diff --git a/tests/__tests__/components/Form.vue b/tests/__tests__/components/Form.vue new file mode 100644 index 00000000..e2516772 --- /dev/null +++ b/tests/__tests__/components/Form.vue @@ -0,0 +1,18 @@ + + + \ No newline at end of file