Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/vue-testing-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.8.2
Choose a base ref
...
head repository: testing-library/vue-testing-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.8.3
Choose a head ref
  • 7 commits
  • 7 files changed
  • 6 contributors

Commits on Aug 1, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c25b1aa View commit details

Commits on Aug 6, 2021

  1. docs: update vue-i18n example url (#248)

    Andrew Luca authored Aug 6, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b16a06b View commit details

Commits on Sep 27, 2021

  1. chore: upgrade to Jest 27 (#251)

    * chore: upgrade to Jest 27
    
    * chore: replace vue-jest with vue2-jest for Jest 27
    
    * chore: fix lint error
    
    * chore: upgrade msw for bug fix
    
    * chore: update expected test error
    
    * chore: check for type errors based on Node version
    nickserv authored Sep 27, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a620424 View commit details

Commits on Jan 7, 2022

  1. docs: Update readme with typescript requirement (#236)

    Specific typescript version is required
    
    Co-authored-by: Adrià Fontcuberta <[email protected]>
    sahbi-ktifa and afontcu authored Jan 7, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0971eb2 View commit details

Commits on Jan 21, 2022

  1. Update README.md

    afontcu authored Jan 21, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4608b37 View commit details

Commits on Mar 1, 2022

  1. Update README.md

    afontcu authored Mar 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4316bd3 View commit details

Commits on May 9, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    181765f View commit details
Showing with 39 additions and 11 deletions.
  1. +14 −1 README.md
  2. +1 −1 jest.config.js
  3. +4 −3 package.json
  4. +6 −1 src/__tests__/about-vue-router-mocha.js
  5. +1 −1 src/__tests__/disappearance.js
  6. +7 −0 src/__tests__/vuex.js
  7. +6 −4 types/index.d.ts
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@
<p>Simple and complete Vue.js testing utilities that encourage good testing practices.</p>

<p>Vue Testing Library is a lightweight adapter built on top of <a href="https://github.com/testing-library/dom-testing-library/">DOM Testing Library</a> and <a href="https://github.com/vuejs/vue-test-utils">@vue/test-utils</a>.</p>


<br />

<p>If you're looking for the Vue 3 version of Vue Testing Library, check out the <a href="https://github.com/testing-library/vue-testing-library/tree/next">next</a> branch.</p>

<br />

@@ -61,6 +66,12 @@
This module is distributed via `npm` and should be installed as one of your
project's `devDependencies`:

If using Vue 2
```
npm install --save-dev @testing-library/vue@5
```

If using Vue 3
```
npm install --save-dev @testing-library/vue
```
@@ -173,6 +184,8 @@ light-weight, simple, and understandable.

## Typings

_Please note that TypeScript 4.X is required._

The TypeScript type definitions are in the [types][types-directory] directory.

## ESLint support
@@ -266,6 +279,6 @@ instead of filing an issue on GitHub.
[vuex-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/vuex.js
[vue-router-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/vue-router.js
[vee-validate-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/validate-plugin.js
[vue-i18n-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/translations-vue-i18n.js.js
[vue-i18n-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/translations-vue-i18n.js
[vuetify-example]: https://github.com/testing-library/vue-testing-library/blob/main/src/__tests__/vuetify.js
<!-- prettier-ignore-end -->
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ module.exports = merge(config, {
collectCoverageFrom: ['**/src/**/*.js', '!**/src/__tests__/**'],
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/@vue/vue2-jest',
},
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
testPathIgnorePatterns: [
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/user-event": "^12.1.10",
"@types/estree": "0.0.46",
"@vue/vue2-jest": "^27.0.0-alpha.2",
"apollo-boost": "^0.4.9",
"apollo-cache-inmemory": "^1.6.6",
"axios": "^0.21.1",
@@ -62,16 +63,16 @@
"graphql-tag": "^2.11.0",
"isomorphic-unfetch": "^3.0.0",
"jest-serializer-vue": "^2.0.2",
"kcd-scripts": "^10.1.1",
"kcd-scripts": "^11.1.0",
"lodash.merge": "^4.6.2",
"msw": "^0.26.2",
"msw": "^0.35.0",
"portal-vue": "^2.1.7",
"semver": "^7.3.5",
"typescript": "^4.0.5",
"vee-validate": "^2.2.15",
"vue": "^2.6.12",
"vue-apollo": "^3.0.4",
"vue-i18n": "^8.21.1",
"vue-jest": "^4.0.0-rc.0",
"vue-router": "^3.4.9",
"vue-template-compiler": "^2.6.12",
"vuetify": "^2.3.17",
7 changes: 6 additions & 1 deletion src/__tests__/about-vue-router-mocha.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@testing-library/jest-dom'
import {render} from '@testing-library/vue'
import semver from 'semver'

import About from './components/Router/About.vue'

@@ -11,6 +12,10 @@ test('uses require("vue-router").default when require("vue-router") is undefined
})

expect(() => render(About, {routes})).toThrowError(
new TypeError("Cannot read property 'default' of undefined"),
new TypeError(
semver.gte(process.version, '16.0.0')
? "Cannot read properties of undefined (reading 'default')"
: "Cannot read property 'default' of undefined",
),
)
})
2 changes: 1 addition & 1 deletion src/__tests__/disappearance.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ test('waits for the data to be loaded', async () => {

// Following line reads as follows:
// "Wait until element with text 'Loading...' is gone."
await waitForElementToBeRemoved(getByText('Loading...'))
await waitForElementToBeRemoved(queryByText('Loading...'))
// It is equivalent to:
//
// await waitFor(() => {
7 changes: 7 additions & 0 deletions src/__tests__/vuex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@testing-library/jest-dom'
import {render, fireEvent} from '@testing-library/vue'
import Vue from 'vue'
import Vuex from 'vuex'

import VuexTest from './components/Store/VuexTest'
@@ -57,6 +58,12 @@ test('can render with vuex with custom store', async () => {
})

test('can render with an instantiated Vuex store', async () => {
// Before calling new Vuex.Store in your code, you'll need to `.use` it on the
// global (or local) Vue instance. In frameworks like Jest, the `setupFilesAfterEnv`
// property is a good place to do this.
// https://jestjs.io/docs/configuration#setupfilesafterenv-array
Vue.use(Vuex)

const {getByTestId, getByText} = render(VuexTest, {
store: new Vuex.Store({
state: {count: 3},
10 changes: 6 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -41,11 +41,11 @@ type Routes = any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Router = any

export interface RenderOptions<V extends Vue>
export interface RenderOptions<V extends Vue, S = Store>
// The props and store options special-cased by Vue Testing Library and NOT passed to mount().
extends Omit<ThisTypedMountOptions<V>, 'store' | 'props'> {
props?: object
store?: Store
store?: S
routes?: Routes
container?: Element
baseElement?: Element
@@ -61,9 +61,11 @@ export type ConfigurationCallback<V extends Vue> =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| ((localVue: typeof Vue, store: Store, router: Router) => void)

export function render<V extends Vue>(
export function render<V extends Vue, S = Store>(
TestComponent: VueClass<V> | ComponentOptions<V>,
options?: RenderOptions<V>,
// eslint-disable-next-line @typescript-eslint/ban-tslint-comment
// tslint:disable-next-line no-unnecessary-generics
options?: RenderOptions<V, S>,
configure?: ConfigurationCallback<V>,
): RenderResult