Skip to content

Commit 7cf4b79

Browse files
committed
Fix directive example
1 parent be034f3 commit 7cf4b79

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/__tests__/directive.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
test.todo('Your test suite must contain at least one test.')
1+
import {render} from '@testing-library/vue'
2+
import '@testing-library/jest-dom'
3+
import {uppercaseDirective} from './directives/uppercase-directive'
4+
import ComponentUsingDirective from './components/Directive'
25

3-
// import {render} from '@testing-library/vue'
4-
// import '@testing-library/jest-dom'
5-
// import {uppercaseDirective} from './directives/uppercase-directive'
6-
// import Directive from './components/Directive'
6+
test('Component with a custom directive', () => {
7+
const {queryByText, getByText} = render(ComponentUsingDirective, {
8+
global: {
9+
directives: {uppercase: uppercaseDirective},
10+
},
11+
})
712

8-
// test('Component with a custom directive', () => {
9-
// // Do not forget to add the new custom directive to the render function as
10-
// // the third parameter.
11-
// const {queryByText, getByText} = render(Directive, {}, vue =>
12-
// vue.directive('uppercase', uppercaseDirective),
13-
// )
13+
// Test that the text in lower case does not appear in the DOM
14+
expect(queryByText('example text')).not.toBeInTheDocument()
1415

15-
// // Test that the text in lower case does not appear in the DOM
16-
// expect(queryByText('example text')).not.toBeInTheDocument()
17-
18-
// // Test that the text in upper case does appear in the DOM thanks to the directive
19-
// expect(getByText('EXAMPLE TEXT')).toBeInTheDocument()
20-
// })
16+
// Test that the text in upper case does appear in the DOM thanks to the directive
17+
expect(getByText('EXAMPLE TEXT')).toBeInTheDocument()
18+
})
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// This function converts the received text passed to the
2-
// v-uppercase directive used in the Directive.vue component
3-
// to upper case and this is appended to the <p> element
4-
export function uppercaseDirective(el, binding) {
5-
el.innerHTML = binding.value.toUpperCase()
1+
// This directive converts any text into its uppercase version
2+
export const uppercaseDirective = {
3+
beforeMount(el, binding) {
4+
el.innerHTML = binding.value.toUpperCase()
5+
},
66
}

0 commit comments

Comments
 (0)