Skip to content

Commit 392e1c0

Browse files
authored
Merge pull request #65 from vuejs/feat/add-props-accessor
Add props accessor method
2 parents 2e7ee68 + 67dc27e commit 392e1c0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/vue-wrapper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export class VueWrapper<T extends ComponentPublicInstance>
4646
return this.componentVM
4747
}
4848

49+
props(selector?: string) {
50+
return selector
51+
? this.componentVM.$props[selector]
52+
: this.componentVM.$props
53+
}
54+
4955
classes(className?: string) {
5056
return new DOMWrapper(this.element).classes(className)
5157
}

tests/props.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { mount } from '../src'
2+
import WithProps from './components/WithProps.vue'
3+
import Hello from './components/Hello.vue'
4+
5+
describe('props', () => {
6+
it('returns a single prop applied to a component', () => {
7+
const wrapper = mount(WithProps, { props: { msg: 'ABC' } })
8+
expect(wrapper.props('msg')).toEqual('ABC')
9+
})
10+
11+
it('returns all props applied to a component', () => {
12+
const wrapper = mount(WithProps, { props: { msg: 'ABC' } })
13+
expect(wrapper.props()).toEqual({ msg: 'ABC' })
14+
})
15+
16+
it('returns undefined if props does not exist', () => {
17+
const wrapper = mount(WithProps, { props: { msg: 'ABC' } })
18+
expect(wrapper.props('foo')).toEqual(undefined)
19+
})
20+
21+
it('returns empty object for components without props', () => {
22+
const wrapper = mount(Hello)
23+
expect(wrapper.props()).toEqual({})
24+
})
25+
})

0 commit comments

Comments
 (0)