Skip to content

add unit test for dynamic component with props #4570

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 1 commit into from
Dec 27, 2016
Merged
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
add unit test for dynamic with props
add unit test for dynamic component with props
  • Loading branch information
bluemsn authored Dec 26, 2016
commit be95f11ff71b9311af639b34945c209db8401ed4
37 changes: 33 additions & 4 deletions test/unit/features/component/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,52 @@ describe('Component', () => {
},
components: {
'view-a': {
template: '<div>foo</div>',
template: '<div>foo {{view}}</div>',
data () {
return { view: 'a' }
}
},
'view-b': {
template: '<div>bar</div>',
template: '<div>bar {{view}}</div>',
data () {
return { view: 'b' }
}
}
}
}).$mount()
expect(vm.$el.outerHTML).toBe('<div view="view-a">foo</div>')
expect(vm.$el.outerHTML).toBe('<div view="view-a">foo a</div>')
vm.view = 'view-b'
waitForUpdate(() => {
expect(vm.$el.outerHTML).toBe('<div view="view-b">bar</div>')
expect(vm.$el.outerHTML).toBe('<div view="view-b">bar b</div>')
vm.view = ''
})
.then(() => {
expect(vm.$el.nodeType).toBe(8)
expect(vm.$el.data).toBe('')
}).then(done)
})

it('dynamic with props', done => {
const vm = new Vue({
template: '<component :is="view" :view="view"></component>',
data: {
view: 'view-a'
},
components: {
'view-a': {
template: '<div>foo {{view}}</div>',
props: ['view']
},
'view-b': {
template: '<div>bar {{view}}</div>',
props: ['view']
}
}
}).$mount()
expect(vm.$el.outerHTML).toBe('<div>foo view-a</div>')
vm.view = 'view-b'
waitForUpdate(() => {
expect(vm.$el.outerHTML).toBe('<div>bar view-b</div>')
vm.view = ''
})
.then(() => {
Expand Down