Skip to content

feat: export createWrapper #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)!!!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!!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)
})
})