-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from vuejs/feat/document-attrs-fallback
feat: Explain how to replace attrs with props
- Loading branch information
Showing
2 changed files
with
53 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
import { defineComponent, h } from 'vue' | ||
|
||
import WithProps from '../components/WithProps.vue' | ||
import { mount } from '../../src' | ||
|
||
test('mounting options - passes props', () => { | ||
const Component = defineComponent({ | ||
props: { | ||
message: { | ||
type: String, | ||
required: true | ||
describe('mountingOptions.props', () => { | ||
test('passes props', () => { | ||
const Component = defineComponent({ | ||
props: { | ||
message: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
|
||
render() { | ||
return h('div', {}, `Message is ${this.message}`) | ||
} | ||
}, | ||
}) | ||
|
||
render() { | ||
return h('div', {}, `Message is ${this.message}`) | ||
} | ||
const wrapper = mount(Component, { | ||
props: { | ||
message: 'Hello' | ||
} | ||
}) | ||
expect(wrapper.text()).toBe('Message is Hello') | ||
}) | ||
|
||
test('assigns extra attributes on components', () => { | ||
const wrapper = mount(WithProps, { | ||
props: { | ||
class: 'HelloFromTheOtherSide', | ||
id: 'hello', | ||
disabled: true, | ||
msg: 'Hello World' | ||
} | ||
}) | ||
|
||
expect(wrapper.attributes()).toEqual({ | ||
class: 'HelloFromTheOtherSide', | ||
disabled: 'true', | ||
id: 'hello' | ||
}) | ||
|
||
expect(wrapper.props()).toEqual({ | ||
msg: 'Hello World' | ||
}) | ||
}) | ||
|
||
const wrapper = mount(Component, { | ||
props: { | ||
message: 'Hello' | ||
test('assigns event listeners', async () => { | ||
const Component = { | ||
template: '<button @click="$emit(\'customEvent\', true)">Click</button>' | ||
} | ||
const onCustomEvent = jest.fn() | ||
const wrapper = mount(Component, { props: { onCustomEvent } }) | ||
const button = wrapper.find('button') | ||
await button.trigger('click') | ||
await button.trigger('click') | ||
await button.trigger('click') | ||
|
||
expect(onCustomEvent).toHaveBeenCalledTimes(3) | ||
}) | ||
expect(wrapper.text()).toBe('Message is Hello') | ||
}) |