Test fails when <router-view></router-view> is an element inside the component
See original GitHub issueFor the following component the test fails but succeeds when i remove the <router-view></router-view>
Teams.vue
<template>
<div class="teams card">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Teams</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="team in teams">
<td>
<span v-show="!team.editing">{{team.name}}</span>
<input type="text" class="form-control" v-model="team.name" v-show="team.editing" />
</td>
<td>
<router-link :to="modalFor(team)">Edit</router-link>
</td>
</tr>
</tbody>
</table>
</div>
<router-view></router-view>
</div>
</template>
<script>
import { Team } from '../../../models/team'
import Modal from '../../../components/Modal'
export default {
components: {Modal},
name: 'teams',
mounted () {
// load all teams
Team.all().then(teams => {
// disable editing mode for all teams
teams.forEach(team => { team.editing = false })
this.teams = teams
})
},
data () {
return {
teams: [],
}
},
methods: {
modalFor (team) {
return '/admin/teams/' + team.id
}
}
}
Teams.spec.js
import Teams from '@/pages/dashboard/admin/Teams'
import { mount } from 'avoriaz'
describe('Teams.vue', () => {
it('should render correct contents', () => {
const wrapper = mount(Teams)
const tableHeader = wrapper.find('.table tr th')[0]
expect(tableHeader.text()).to.equal('Teams')
})
})
The test result with the <router-view>
inside the component:
The test result without the <router-view>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Generated test fails when unit testing component inside the ...
I just encountered the same problem. Using Nrwl's Nx to scaffold a new application plus a "feature-shell" library (the design pattern ...
Read more >Testing React components - Apollo GraphQL Docs
This article describes best practices for testing React components that use Apollo Client. The examples below use Jest and React Testing Library, ...
Read more >Testing Components – Testing Angular
Introduction to testing Angular Components with Angular's TestBed. ... For accessing elements in the DOM, Angular has another abstraction: ...
Read more >router view
If not passed then will be determined based on whether its element has ... The `router-link` Component in Vue. vue and change the...
Read more >How to Test React Components: the Complete Guide
The tests will pass if your hypothesis is correct and fail if it is wrong. Unlike your react components, your tests are not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
router-view is injected as a global component when you Vue.use() vue-router.
You need to register a mock global component:
You can mock
$route
😄globals
adds properties to the Vue prototype, so they are accessible inside eachvm
.