根据$route.params
或$route.query
,我有一个Vue.js组件具有不同的行为。类似的东西:
<template>
<div class="hello">
{{query}}
</div>
</template>
<script>
export default {
name: 'hello',
data () {
return {
}
}
},
computed: {
'query': () => {
return $route.params.query
}
}
}
</script>
如何编写单元测试规范,以编程方式设置$route.params
或$route.query
的值?
这样的事情:
import Vue from 'vue'
import Template from '@/components/Template'
describe('Template.vue', () => {
it('should render according to query', () => {
const Constructor = Vue.extend(Script)
const vm = new Constructor()
vm.$route = { // THIS DOES NOT WORK
params: {
id: 1
}
}
vm.$mount()
// Test contents
})
})
失败
setting a property that has only a getter