Skip to content

add simple directive and test #110

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

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 14 additions & 0 deletions src/__tests__/components/CompWithDirective.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<input v-value="value" />
</template>

<script>
export default {
props: {
value: {
type: String,
required: true,
},
},
}
</script>
3 changes: 3 additions & 0 deletions src/__tests__/components/directives/v-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function value(el, binding) {
el.value = binding.value
}
18 changes: 18 additions & 0 deletions src/__tests__/use-global-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import '@testing-library/jest-dom/extend-expect'
import {render, wait} from '@testing-library/vue'
import {value as valueDirective} from './components/directives/v-value'
import CompWithDirective from './components/CompWithDirective.vue'

test('element should have the same value as the directive', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

I feel the example is a bit "wordy" (it says value a lot 😝).

I think it would be best if we used a simpler example with a clearer directive. Also I'd love to avoid using updateProps, as it has actually nothing to do with directives, and people may get the wrong impression.

What do you think about that?

const value = 'test'
const {container, updateProps} = render(
CompWithDirective,
{props: {value}},
vue => vue.directive('value', valueDirective),
)
await wait()
expect(container.firstChild).toHaveValue(value)
const anotherValue = 'another'
await updateProps({value: anotherValue})
expect(container.firstChild).toHaveValue(anotherValue)
})