-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add directive test example (#120)
* Add directive folder to test path ignore patterns to jest config * Implement v-uppercase directive * Implement Directive example component * Implement directive test
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<div> | ||
<p v-uppercase="text" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
text: 'example text', | ||
} | ||
}, | ||
} | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {render} from '@testing-library/vue' | ||
import '@testing-library/jest-dom/extend-expect' | ||
import {uppercaseDirective} from './directives/uppercase-directive' | ||
import Directive from './components/Directive' | ||
|
||
// We are about to test an easy vue directive, that we have implemented, | ||
// named v-uppercawse. | ||
test('Component with a custom directive', () => { | ||
// Do not forget to add the new custom directive to the render function as | ||
// the third parameter. | ||
const {queryByText} = render(Directive, {}, vue => | ||
vue.directive('uppercase', uppercaseDirective), | ||
) | ||
|
||
// Test that the text in lower case does not appear in the DOM | ||
expect(queryByText('example text')).not.toBeInTheDocument() | ||
|
||
// Test that the text in upper case does appear in the DOM thanks to the directive | ||
expect(queryByText('EXAMPLE TEXT')).toBeInTheDocument() | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This function converts the received text passed to the | ||
// v-uppercase directive used in the Directive.vue component | ||
// to upper case and this is appended to the <p> element | ||
export function uppercaseDirective(el, binding) { | ||
el.innerHTML = binding.value.toUpperCase() | ||
} |