Skip to content

Commit

Permalink
feat: export createWrapper method to create wrapper from instance (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Jul 29, 2018
1 parent c212ebf commit ebca3b3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
!!!include(docs/api/renderToString.md)!!!
!!!include(docs/api/selectors.md)!!!
!!!include(docs/api/createLocalVue.md)!!!
!!!include(docs/api/createWrapper.md)!!!
!!!include(docs/api/config.md)!!!
19 changes: 19 additions & 0 deletions docs/api/createWrapper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## createWrapper()

- **Returns:**
- `{Wrapper}`

- **Usage:**

`createWrapper` creates a `Wrapper` for a mounted Vue instance, or an HTML element.

```js
import { createWrapper } from '@vue/test-utils'
import Foo from './Foo.vue'

const Constructor = Vue.extend(Foo)
const vm = new Constructor().$mount()
const wrapper = createWrapper(vm)
expect(wrapper.vm.foo).toBe(true)
```

2 changes: 1 addition & 1 deletion flow/wrapper.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ declare interface BaseWrapper {

declare type WrapperOptions = {
// eslint-disable-line no-undef
attachedToDocument: boolean,
attachedToDocument?: boolean,
sync?: boolean
};
2 changes: 1 addition & 1 deletion packages/test-utils/src/create-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import VueWrapper from './vue-wrapper'

export default function createWrapper (
node: VNode | Component,
options: WrapperOptions
options: WrapperOptions = {}
): VueWrapper | Wrapper {
const componentInstance = node.componentInstance || node.child
if (componentInstance) {
Expand Down
2 changes: 2 additions & 0 deletions packages/test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import createLocalVue from './create-local-vue'
import TransitionStub from './components/TransitionStub'
import TransitionGroupStub from './components/TransitionGroupStub'
import RouterLinkStub from './components/RouterLinkStub'
import createWrapper from './create-wrapper'
import Wrapper from './wrapper'
import WrapperArray from './wrapper-array'
import config from './config'
Expand All @@ -19,6 +20,7 @@ function shallow (component, options) {

export default {
createLocalVue,
createWrapper,
config,
mount,
shallow,
Expand Down
15 changes: 15 additions & 0 deletions test/specs/create-wrapper.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Vue from 'vue'
import { createWrapper, Wrapper, WrapperArray } from '~vue/test-utils'
import Component from '~resources/components/component.vue'
import { describeRunIf } from 'conditional-specs'

describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
it.only('exports createWrapper', () => {
const Constructor = Vue.extend(Component)
const vm = new Constructor().$mount()
const wrapper = createWrapper(vm)
expect(wrapper.is(Component)).to.equal(true)
expect(wrapper).instanceof(Wrapper)
expect(wrapper.findAll('div')).instanceof(WrapperArray)
})
})

0 comments on commit ebca3b3

Please sign in to comment.