Skip to content

Commit bb34569

Browse files
eddyerburghkuitos
authored andcommitted
docs: add arguments to createWrapper.md (vuejs#869)
1 parent 7120621 commit bb34569

File tree

7 files changed

+47
-10
lines changed

7 files changed

+47
-10
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
- attach_workspace:
104104
at: ~/repo
105105
- *restore_node_modules
106-
- run: yarn test:compat "2.5.13"
106+
- run: yarn test:compat "2.5.16"
107107
workflows:
108108
version: 2
109109
install-tests:

docs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ Vue Test Utils is the official unit testing utility library for Vue.js.
7878
* [TransitionGroupStub](api/components/TransitionGroupStub.md)
7979
* [RouterLinkStub](api/components/RouterLinkStub.md)
8080
* [Selectors](api/selectors.md)
81+
* [createWrapper](api/createWrapper.md)
8182
* [createLocalVue](api/createLocalVue.md)
8283
* [config](api/config.md)

docs/api/createWrapper.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
## createWrapper()
1+
## createWrapper(node, options)
2+
3+
- **Arguments:**
4+
5+
- `{vm|HTMLElement} node`
6+
- `{Object} options`
7+
- `{Boolean} sync`
8+
- `{Boolean} attachedToDocument
29

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

packages/test-utils/types/index.d.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ interface BaseWrapper {
8181
destroy (): void
8282
}
8383

84-
export interface Wrapper<V extends Vue> extends BaseWrapper {
84+
export interface Wrapper<V extends Vue | null> extends BaseWrapper {
8585
readonly vm: V
8686
readonly element: HTMLElement
8787
readonly options: WrapperOptions
@@ -117,8 +117,8 @@ export interface WrapperArray<V extends Vue> extends BaseWrapper {
117117
}
118118

119119
interface WrapperOptions {
120-
attachedToDocument: boolean
121-
sync: boolean
120+
attachedToDocument?: boolean
121+
sync?: boolean
122122
}
123123

124124
interface MountOptions<V extends Vue> extends ComponentOptions<V> {
@@ -161,6 +161,9 @@ export declare function shallowMount<V extends Vue> (component: VueClass<V>, opt
161161
export declare function shallowMount<V extends Vue> (component: ComponentOptions<V>, options?: ThisTypedShallowMountOptions<V>): Wrapper<V>
162162
export declare function shallowMount (component: FunctionalComponentOptions, options?: ShallowMountOptions<Vue>): Wrapper<Vue>
163163

164+
export declare function createWrapper(node: Vue, options?: WrapperOptions): Wrapper<Vue>
165+
export declare function createWrapper(node: HTMLElement, options?: WrapperOptions): Wrapper<null>
166+
164167
export declare let TransitionStub: Component | string | true
165168
export declare let TransitionGroupStub: Component | string | true
166169
export declare let RouterLinkStub: VueClass<Vue>

packages/test-utils/types/test/wrapper.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { mount } from '../'
1+
import { mount, createWrapper } from '../'
22
import { normalOptions, functionalOptions, Normal, ClassComponent } from './resources'
3+
import Vue from 'vue'
34

45
/**
56
* Tests for BaseWrapper API
@@ -47,8 +48,6 @@ wrapper.vm.$emit('event', 'arg')
4748

4849
let el: HTMLElement = wrapper.element
4950

50-
bool = wrapper.options.attachedToDocument
51-
5251
let found = wrapper.find('.foo')
5352
found = wrapper.find(normalOptions)
5453
found = wrapper.find(functionalOptions)
@@ -78,3 +77,14 @@ str = wrapper.name()
7877
let num: number = array.length
7978
found = array.at(1)
8079
array = array.filter((a: any) => a === true)
80+
81+
let createdWrapper = createWrapper(new Vue().$mount())
82+
createdWrapper.text()
83+
createWrapper(document.createElement('div'))
84+
createWrapper(document.createElement('div'), {
85+
sync: false,
86+
attachedToDocument: true
87+
})
88+
createWrapper(document.createElement('div'), {
89+
attachedToDocument: true
90+
})

scripts/test-compat-all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ scripts/test-compat.sh "2.1.10"
77
scripts/test-compat.sh "2.2.6"
88
scripts/test-compat.sh "2.3.4"
99
scripts/test-compat.sh "2.4.2"
10-
scripts/test-compat.sh "2.5.13"
10+
scripts/test-compat.sh "2.5.16"

test/specs/create-wrapper.spec.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@ import Component from '~resources/components/component.vue'
44
import { describeRunIf } from 'conditional-specs'
55

66
describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
7-
it.only('exports createWrapper', () => {
7+
it('exports createWrapper', () => {
88
const Constructor = Vue.extend(Component)
99
const vm = new Constructor().$mount()
1010
const wrapper = createWrapper(vm)
1111
expect(wrapper.is(Component)).to.equal(true)
1212
expect(wrapper).instanceof(Wrapper)
1313
expect(wrapper.findAll('div')).instanceof(WrapperArray)
1414
})
15+
16+
it('handles HTMLElement', () => {
17+
const wrapper = createWrapper(document.createElement('div'))
18+
expect(wrapper.is('div')).to.equal(true)
19+
})
20+
21+
it('handles options', () => {
22+
const Constructor = Vue.extend(Component)
23+
const vm = new Constructor().$mount()
24+
const wrapper = createWrapper(vm, {
25+
sync: true,
26+
attachToDocument: true
27+
})
28+
expect(wrapper.options.attachToDocument).to.equal(true)
29+
expect(wrapper.options.sync).to.equal(true)
30+
})
1531
})

0 commit comments

Comments
 (0)