Skip to content

Commit 105a8f8

Browse files
committed
docs(cypress): document selectDate and vModelAdapter
1 parent 650e047 commit 105a8f8

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

packages/e2e-cypress/README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ This App Extension (AE) manages Quasar and Cypress integration for you, both for
3232

3333
Some custom commands are included out-of-the-box:
3434

35-
| Name | Usage | Description |
36-
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37-
| `dataCy` | `cy.dataCy('my-data-id')` | Implements the [selection best practice](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements) which avoids brittle tests, is equivalent to `cy.get('[data-cy=my-data-id]')` |
38-
| `testRoute` | `cy.testRoute('home')` <br /> `cy.testRoute('books/*/pages/*')` | Tests if the current URL matches the provided string using [`minimatch`](https://docs.cypress.io/api/utilities/minimatch). Leading `#`, if using router hash mode, and `/` are automatically prepended. |
39-
| `within[Portal\|Menu\|SelectMenu\|Dialog]` | `cy.withinSelectMenu(() => cy.get('.q-item').first().click())` <br /> `cy.withinDialog({ dataCy: 'add-action-dialog', fn() { /* business haha */ } });` | Auto-scope commands into the callback within the Portal-based component and perform assertions common to all of them. |
40-
| `should('have.[color\|backgroundColor]')` | `cy.get('foo').should('have.color', 'white')` <br /> `cy.get('foo').should('have.backgroundColor', '#000')` <br /> `cy.get('foo').should('have.color', 'var(--q-primary)')` | Provide a couple color-related custom matchers, which accept any valid CSS color format. |
35+
| Name | Usage | Description |
36+
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37+
| `dataCy` | `cy.dataCy('my-data-id')` | Implement the [selection best practice](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements) which avoids brittle tests, is equivalent to `cy.get('[data-cy=my-data-id]')` |
38+
| `selectDate` | `cy.get('.q-date').selectDate('2023/02/23')` | Select a given date into a QDate component, it accept either a `Date` object or a string which `new Date(myDate)` can parse correctly |
39+
| `testRoute` | `cy.testRoute('home')` <br /> `cy.testRoute('books/*/pages/*')` | Test if the current URL matches the provided string using [`minimatch`](https://docs.cypress.io/api/utilities/minimatch). Leading `#`, if using router hash mode, and `/` are automatically prepended. |
40+
| `within[Portal\|Menu\|SelectMenu\|Dialog]` | `cy.withinSelectMenu(() => cy.get('.q-item').first().click())` <br /> `cy.withinDialog({ dataCy: 'add-action-dialog', fn() { /* business haha */ } });` | Auto-scope commands into the callback within the Portal-based component and perform assertions common to all of them. |
41+
| `should('have.[color\|backgroundColor]')` | `cy.get('foo').should('have.color', 'white')` <br /> `cy.get('foo').should('have.backgroundColor', '#000')` <br /> `cy.get('foo').should('have.color', 'var(--q-primary)')` | Provide a couple color-related custom matchers, which accept any valid CSS color format. |
42+
43+
> Check out how to use these commands, and other recipes about testing Quasar UI components, into our [automated tests suite](./src/templates/typescript/src/components/___tests__).
4144
4245
You must have a running dev server in order to run integration tests. The scripts added by this AE automatically take care of this: `yarn test:e2e` and `yarn test:e2e:ci` will launch `quasar dev` when starting up the tests and kill it when cypress process ends.
4346

@@ -178,6 +181,24 @@ The good news is that we don't actually need to, since official documentation fo
178181
- [Vuex](https://docs.cypress.io/guides/component-testing/custom-mount-vue#Vuex)
179182
- [Pinia](https://pinia.vuejs.org/cookbook/testing.html#unit-testing-components)
180183

184+
#### Using vModel into your tests
185+
186+
Vue Test Utils doesn't provide an helper to test your components vModel, so we created our own, which even allow you use refs into your tests, based on [this discussion](https://github.com/vuejs/test-utils/discussions/279).
187+
188+
```ts
189+
const model = ref(null);
190+
mount(QSelect, {
191+
props: {
192+
...vModelAdapter(model),
193+
// or, if you're using a custom name for your vModel, use
194+
// ...vModelAdapter(model, 'myModelName'),
195+
options,
196+
},
197+
});
198+
```
199+
200+
Check out more examples [here](./src/templates/typescript/src/components/___tests__/VModelComponent.cy.ts).
201+
181202
### Testing the AE
182203

183204
```sh

packages/e2e-cypress/src/helpers/v-model-adapter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Ref, watch } from 'vue';
22

3-
// TODO: not properly documented into the README
4-
53
// VTU won't accept reactive v-model binding, this adapter manually
64
// set the model prop each time a new value is emitted
75
// See https://github.com/vuejs/test-utils/discussions/279

0 commit comments

Comments
 (0)