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

replace TestingApiSwitcher with VTCodeGroup #2595

Merged
merged 1 commit into from
Dec 13, 2023
Merged
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
119 changes: 0 additions & 119 deletions src/guide/scaling-up/TestingApiSwitcher.vue

This file was deleted.

96 changes: 46 additions & 50 deletions src/guide/scaling-up/testing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import TestingApiSwitcher from './TestingApiSwitcher.vue'
import { VTCodeGroup, VTCodeGroupTab } from '@vue/theme'
</script>

# Testing {#testing}
Expand Down Expand Up @@ -126,72 +126,68 @@ Component tests should focus on the component's public interfaces rather than in

We know nothing about the implementation of Stepper, only that the "input" is the `max` prop and the "output" is the state of the DOM as the user will see it.

<TestingApiSwitcher>
<VTCodeGroup>
<VTCodeGroupTab label="Vue Test Utils">

<div class="testing-library-api">
```js
const valueSelector = '[data-testid=stepper-value]'
const buttonSelector = '[data-testid=increment]'

```js
const { getByText } = render(Stepper, {
props: {
max: 1
}
})

getByText('0') // Implicit assertion that "0" is within the component

const button = getByRole('button', { name: /increment/i })

// Dispatch a click event to our increment button.
await fireEvent.click(button)
const wrapper = mount(Stepper, {
props: {
max: 1
}
})

getByText('1')
expect(wrapper.find(valueSelector).text()).toContain('0')

await fireEvent.click(button)
```
await wrapper.find(buttonSelector).trigger('click')

</div>
expect(wrapper.find(valueSelector).text()).toContain('1')
```

<div class="vtu-api">
</VTCodeGroupTab>
<VTCodeGroupTab label="Cypress">

```js
const valueSelector = '[data-testid=stepper-value]'
const buttonSelector = '[data-testid=increment]'
```js
const valueSelector = '[data-testid=stepper-value]'
const buttonSelector = '[data-testid=increment]'

const wrapper = mount(Stepper, {
props: {
max: 1
}
})

expect(wrapper.find(valueSelector).text()).toContain('0')
mount(Stepper, {
props: {
max: 1
}
})

await wrapper.find(buttonSelector).trigger('click')
cy.get(valueSelector).should('be.visible').and('contain.text', '0')
.get(buttonSelector).click()
.get(valueSelector).should('contain.text', '1')
```

expect(wrapper.find(valueSelector).text()).toContain('1')
```
</VTCodeGroupTab>
<VTCodeGroupTab label="Testing Library">

</div>
```js
const { getByText } = render(Stepper, {
props: {
max: 1
}
})

<div class="cypress-api">
getByText('0') // Implicit assertion that "0" is within the component

```js
const valueSelector = '[data-testid=stepper-value]'
const buttonSelector = '[data-testid=increment]'
const button = getByRole('button', { name: /increment/i })

mount(Stepper, {
props: {
max: 1
}
})
// Dispatch a click event to our increment button.
await fireEvent.click(button)

cy.get(valueSelector).should('be.visible').and('contain.text', '0')
.get(buttonSelector).click()
.get(valueSelector).should('contain.text', '1')
```
getByText('1')

</div>
await fireEvent.click(button)
```

</TestingApiSwitcher>
</VTCodeGroupTab>
</VTCodeGroup>

- **DON'T**

Expand Down