-
Notifications
You must be signed in to change notification settings - Fork 2
Guide: dom-events.md #19
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
# Testing Key, Mouse and other DOM events | ||
# Tester le clavier, la souris et les autres évènements DOM | ||
|
||
## Trigger events | ||
## Déclencheur d'évènements | ||
|
||
The `Wrapper` expose a `trigger` method. It can be used to trigger DOM events. | ||
|
||
Le `Wrapper` expose une méthode `trigger`. Elle peut être utilisée pour déclencher des évènements du DOM. | ||
|
||
```js | ||
const wrapper = mount(MyButton) | ||
|
||
wrapper.trigger('click') | ||
``` | ||
|
||
You should be aware, that find returns a wrapper as well. Assuming `MyComponent` contains a button, the following code clicks the button. | ||
Vous devez être au courant que la méthode `find` retourne un wrapper aussi. Partant du principe que `MyComponent` contient un bouton, le code suivant clique sur le bouton. | ||
|
||
```js | ||
const wrapper = mount(MyComponent) | ||
|
@@ -20,9 +21,9 @@ wrapper.find('button').trigger('click') | |
|
||
## Options | ||
|
||
The trigger method takes an optional `options` object. The properties in the `options` object are added to the Event. | ||
La méthode `trigger` prend en paramètre optionnel l'objet `options`. Les propriétés de l'objet `options` sont ajoutées à l'évènement. | ||
|
||
You can run preventDefault on the event by passing `preventDefault: true` in `options`. | ||
Vous pouvez utiliser `preventDefault` sur l'évènement en passant `preventDefault: true` dans le paramètre `options`. | ||
|
||
```js | ||
const wrapper = mount(MyButton) | ||
|
@@ -31,15 +32,15 @@ wrapper.trigger('click', {preventDefault: true}) | |
``` | ||
|
||
|
||
## Mouse Click Example | ||
## Exemple de clic de souris | ||
|
||
**Component under test** | ||
**Componsant à tester** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Composant |
||
|
||
```js | ||
<template> | ||
<div> | ||
<button class="yes" @click="callYes">Yes</button> | ||
<button class="no" @click="callNo">No</button> | ||
<button class="yes" @click="callYes">Oui</button> | ||
<button class="no" @click="callNo">Non</button> | ||
</div> | ||
</template> | ||
<script> | ||
|
@@ -70,8 +71,8 @@ import YesNoComponent from '@/components/YesNoComponent' | |
import { mount } from 'vue-test-utils' | ||
import sinon from 'sinon' | ||
|
||
describe('Click event', () => { | ||
it('Click on yes button calls our method with argument "yes"', () => { | ||
describe('Évènement click', () => { | ||
it('Cliquer sur le bouton oui appelle notre méthode avec l\'argument "yes"', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Cliquer sur le bouton oui appelle notre méthode avec l'argument 'yes'", on avait fait ça pour les autres fichiers afin d'éviter les backslashs |
||
const spy = sinon.spy() | ||
const wrapper = mount(YesNoComponent, { | ||
propsData: { | ||
|
@@ -85,11 +86,11 @@ describe('Click event', () => { | |
}) | ||
``` | ||
|
||
## Keyboard Example | ||
## Exemple de test clavier | ||
|
||
**Component under test** | ||
**Composant à tester** | ||
|
||
This component allows to increment/decrement the quantity using various keys. | ||
Ce composant permet d'incrémenter / décrémenter la quantité en utilisant différentes touches. | ||
|
||
```js | ||
<template> | ||
|
@@ -148,33 +149,33 @@ export default { | |
import QuantityComponent from '@/components/QuantityComponent' | ||
import { mount } from 'vue-test-utils' | ||
|
||
describe('Key event tests', () => { | ||
it('Quantity is zero by default', () => { | ||
describe('Tests événement clavier', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. évènement |
||
it('La quantité est zéro par défaut', () => { | ||
const wrapper = mount(QuantityComponent) | ||
expect(wrapper.vm.quantity).to.equal(0) | ||
}) | ||
|
||
it('Cursor up sets quantity to 1', () => { | ||
it('La flèche du haut positionne la quantité à 1', () => { | ||
const wrapper = mount(QuantityComponent) | ||
wrapper.trigger('keydown.up') | ||
expect(wrapper.vm.quantity).to.equal(1) | ||
}) | ||
|
||
it('Cursor down reduce quantity by 1', () => { | ||
it('La flèche du bas réduit la quantité de 1', () => { | ||
const wrapper = mount(QuantityComponent) | ||
wrapper.vm.quantity = 5 | ||
wrapper.trigger('keydown.down') | ||
expect(wrapper.vm.quantity).to.equal(4) | ||
}) | ||
|
||
it('Escape sets quantity to 0', () => { | ||
it('La touche Échap positionne la quantité à 0', () => { | ||
const wrapper = mount(QuantityComponent) | ||
wrapper.vm.quantity = 5 | ||
wrapper.trigger('keydown.esc') | ||
expect(wrapper.vm.quantity).to.equal(0) | ||
}) | ||
|
||
it('Magic character "a" sets quantity to 13', () => { | ||
it('Le caractère magique "a" positionne la quantité à 13', () => { | ||
const wrapper = mount(QuantityComponent) | ||
wrapper.trigger('keydown', { | ||
which: 65 | ||
|
@@ -187,10 +188,10 @@ describe('Key event tests', () => { | |
|
||
**Limitations** | ||
|
||
A key name after the dot `keydown.up` is translated to a `keyCode`. This is supported for the following names: | ||
Un nom de touche après le point `keydown.up` est traduit vers un `keyCode`. Cela est supporté pour les noms suivant : | ||
|
||
* enter, tab, delete, esc, space, up, down, left, right | ||
|
||
## Important | ||
|
||
vue-test-utils triggers event synchronously. Consequently, `vue.nextTick` is not required. | ||
vue-test-utils déclenche les évènements de façon synchrone. Par conséquent, `vue.nextTick` n'est pas requis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retourne aussi un wrapper.
En partant du principe