Skip to content
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)
})