Vue.js
の単体テストで計算されたプロパティをどのようにテストするのだろうか。Vue.jsで計算されたプロパティをテストするには? "データ"を模倣できない
vue-cli
(webpack
ベース)で新しいプロジェクトを作成しました。例えば
ここでは私のコンポーネントです:
<script>
export default {
data() {
return {
source: []
}
},
methods: {
removeDuplicates (arr) {
return [...new Set(arr)]
}
},
computed: {
types() {
return this.removeDuplicates(this.source))
}
}
}
</script>
私はこの
it('should remove duplicates from array',() => {
const arr = [1, 2, 1, 2, 3]
const result = FiltersList.computed.types()
const expectedLength = 3
expect(result).to.have.length(expectedLength)
})
QUESTION(二つの問題)のようにそれをテストしようとしました:
this.source
は、undefined
である。それを模倣したり価値を設定する方法は? (FiltersList.data
は関数です)。- おそらく私は
removeDuplicates
メソッドを呼び出すことをwan'tしませんが、この呼び出しを模擬する(スタブ)方法はありますか?
@Theoようこそ)) –