Skip to content

docs: add arguments to createWrapper.md #869

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 4 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- attach_workspace:
at: ~/repo
- *restore_node_modules
- run: yarn test:compat "2.5.13"
- run: yarn test:compat "2.5.16"
workflows:
version: 2
install-tests:
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ Vue Test Utils is the official unit testing utility library for Vue.js.
* [TransitionGroupStub](api/components/TransitionGroupStub.md)
* [RouterLinkStub](api/components/RouterLinkStub.md)
* [Selectors](api/selectors.md)
* [createWrapper](api/createWrapper.md)
* [createLocalVue](api/createLocalVue.md)
* [config](api/config.md)
9 changes: 8 additions & 1 deletion docs/api/createWrapper.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## createWrapper()
## createWrapper(node, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, I think it is necessary to add the test for this option argument.


- **Arguments:**

- `{vm|HTMLElement} node`
- `{Object} options`
- `{Boolean} sync`
- `{Boolean} attachedToDocument

- **Returns:**
- `{Wrapper}`
Expand Down
9 changes: 6 additions & 3 deletions packages/test-utils/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface BaseWrapper {
destroy (): void
}

export interface Wrapper<V extends Vue> extends BaseWrapper {
export interface Wrapper<V extends Vue | null> extends BaseWrapper {
readonly vm: V
readonly element: HTMLElement
readonly options: WrapperOptions
Expand Down Expand Up @@ -117,8 +117,8 @@ export interface WrapperArray<V extends Vue> extends BaseWrapper {
}

interface WrapperOptions {
attachedToDocument: boolean
sync: boolean
attachedToDocument?: boolean
sync?: boolean
}

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

export declare function createWrapper(node: Vue, options?: WrapperOptions): Wrapper<Vue>
export declare function createWrapper(node: HTMLElement, options?: WrapperOptions): Wrapper<null>

export declare let TransitionStub: Component | string | true
export declare let TransitionGroupStub: Component | string | true
export declare let RouterLinkStub: VueClass<Vue>
16 changes: 13 additions & 3 deletions packages/test-utils/types/test/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from '../'
import { mount, createWrapper } from '../'
import { normalOptions, functionalOptions, Normal, ClassComponent } from './resources'
import Vue from 'vue'

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

let el: HTMLElement = wrapper.element

bool = wrapper.options.attachedToDocument

let found = wrapper.find('.foo')
found = wrapper.find(normalOptions)
found = wrapper.find(functionalOptions)
Expand Down Expand Up @@ -78,3 +77,14 @@ str = wrapper.name()
let num: number = array.length
found = array.at(1)
array = array.filter((a: any) => a === true)

let createdWrapper = createWrapper(new Vue().$mount())
createdWrapper.text()
createWrapper(document.createElement('div'))
createWrapper(document.createElement('div'), {
sync: false,
attachedToDocument: true
})
createWrapper(document.createElement('div'), {
attachedToDocument: true
})
2 changes: 1 addition & 1 deletion scripts/test-compat-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ scripts/test-compat.sh "2.1.10"
scripts/test-compat.sh "2.2.6"
scripts/test-compat.sh "2.3.4"
scripts/test-compat.sh "2.4.2"
scripts/test-compat.sh "2.5.13"
scripts/test-compat.sh "2.5.16"
18 changes: 17 additions & 1 deletion test/specs/create-wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ import Component from '~resources/components/component.vue'
import { describeRunIf } from 'conditional-specs'

describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
it.only('exports createWrapper', () => {
it('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)
})

it('handles HTMLElement', () => {
const wrapper = createWrapper(document.createElement('div'))
expect(wrapper.is('div')).to.equal(true)
})

it('handles options', () => {
const Constructor = Vue.extend(Component)
const vm = new Constructor().$mount()
const wrapper = createWrapper(vm, {
sync: true,
attachToDocument: true
})
expect(wrapper.options.attachToDocument).to.equal(true)
expect(wrapper.options.sync).to.equal(true)
})
})