Skip to content

Commit e18bfba

Browse files
authored
Merge pull request #16 from vuejs/alpha-3
Catch up with alpha-3
2 parents ce4ba5d + b80c0f2 commit e18bfba

File tree

2 files changed

+95
-9
lines changed

2 files changed

+95
-9
lines changed

src/.vuepress/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
locales: {
3131
'/': {
3232
lang: 'en-US',
33-
title: 'Vue Test Utils (2.0.0-alpha-2)'
33+
title: 'Vue Test Utils (2.0.0-alpha.3)'
3434
}
3535
},
3636
themeConfig: {

src/api/README.md

+94-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test('mounts on a specific element', () => {
5454
attachTo: document.getElementById('app')
5555
})
5656

57-
console.log(document.body.innerHTML)
57+
console.log(document.body.innerHTML)
5858
/*
5959
* <div>
6060
* <h1>Non Vue app</h1>
@@ -695,23 +695,23 @@ export default {
695695
```js
696696
import Foo from '@/Foo.vue'
697697

698-
test('find', () => {
698+
test('findComponent', () => {
699699
const wrapper = mount(Component)
700700

701701
// All the following queries would return a VueWrapper
702702

703703
// Using a standard querySelector query
704-
wrapper.find('.foo')
705-
wrapper.find('[data-test="foo"]')
704+
wrapper.findComponent('.foo')
705+
wrapper.findComponent('[data-test="foo"]')
706706

707707
// Using component's name
708-
wrapper.find({ name: 'Foo' })
708+
wrapper.findComponent({ name: 'Foo' })
709709

710710
// Using ref attribute. Can be used only on direct children of the mounted component
711-
wrapper.find({ ref: 'foo' })
711+
wrapper.findComponent({ ref: 'foo' })
712712

713713
// Using imported component
714-
wrapper.find(Foo)
714+
wrapper.findComponent(Foo)
715715
})
716716
```
717717

@@ -750,6 +750,92 @@ test('findAllComponents', () => {
750750
})
751751
```
752752

753+
754+
### `get`
755+
756+
Similar to `find`, `get` looks for an element and returns a `DOMWrapper` if one is found. Otherwise it throws an error.
757+
758+
`Component.vue`:
759+
760+
```vue
761+
<template>
762+
<span>Span</span>
763+
<span data-test="span">Span</span>
764+
</template>
765+
```
766+
767+
`Component.spec.js`:
768+
769+
```js
770+
test('get', () => {
771+
const wrapper = mount(Component)
772+
773+
wrapper.get('span') //=> found; returns DOMWrapper
774+
wrapper.get('[data-test="span"]') //=> found; returns DOMWrapper
775+
776+
expect(() => wrapper.getComponent('p')).toThrowError()
777+
})
778+
```
779+
780+
781+
### `getComponent`
782+
783+
Similar to `findComponent`, `getComponent` looks for a Vue Component instance and returns a `VueWrapper` if one is found. Otherwise it throws an error.
784+
785+
**Supported syntax:**
786+
787+
* **querySelector** - `getComponent('.component')` - Matches standard query selector.
788+
* **Name** - `getComponent({ name: 'myComponent' })` - matches PascalCase, snake-case, camelCase
789+
* **ref** - `getComponent({ ref: 'dropdown' })` - Can be used only on direct ref children of mounted component
790+
* **SFC** - `getComponent(ImportedComponent)` - Pass an imported component directly.
791+
792+
`Foo.vue`
793+
794+
```vue
795+
<template>
796+
<div class="foo">
797+
Foo
798+
</div>
799+
</template>
800+
801+
<script>
802+
export default {
803+
name: 'Foo'
804+
}
805+
</script>
806+
```
807+
808+
`Component.vue`:
809+
810+
```vue
811+
<template>
812+
<Foo />
813+
</template>
814+
815+
<script>
816+
import Foo from '@/Foo'
817+
818+
export default {
819+
components: { Foo },
820+
}
821+
</script>
822+
```
823+
824+
`Component.spec.js`
825+
826+
```js
827+
import Foo from '@/Foo.vue'
828+
829+
test('getComponent', () => {
830+
const wrapper = mount(Component)
831+
832+
wrapper.getComponent({ name: 'foo' }) // returns a VueWrapper
833+
wrapper.getComponent(Foo) // returns a VueWrapper
834+
835+
expect(() => wrapper.getComponent('.not-there')).toThrowError()
836+
})
837+
```
838+
753839
### `html`
754840

755841
Returns the HTML (via `outerHTML`) of an element. Useful for debugging.
@@ -814,7 +900,7 @@ test('props', () => {
814900
const wrapper = mount(Component, {
815901
global: { stubs: ['Foo'] }
816902
})
817-
const foo = wrapper.findComponent({ name: 'Foo' })
903+
const foo = wrapper.getComponent({ name: 'Foo' })
818904

819905
expect(foo.props('truthy')).toBe(true)
820906
expect(foo.props('object')).toEqual({})

0 commit comments

Comments
 (0)