如何為此計算撰寫一個 JEST 單元測驗,按型別檢查和過濾:
模板:
鍵入電子郵件:
<CommunicationPreference
v-for="(communication, index) in communicationPreferenceTypeEmail"
:key="index communication.name"
:consent="communication.consent"
:name="communication.name"
@update="updateConsent"
/>
不輸入電子郵件:
<CommunicationPreference
v-for="(communication, index) in communicationPreferenceTypeNotEmail"
:key="index communication.name"
:consent="communication.consent"
:name="communication.name"
@update="updateConsent"
/>
按型別計算檔案管理器,以便我可以在兩個單獨的串列中顯示一個具有一種電子郵件型別的串列,然后一個是其他所有串列:
computed: {
...mapState('account', ['communicationPreferences']),
communicationPreferenceTypeEmail() {
return this.communicationPreferences.filter((e) => e.type === 'EMAIL')
},
communicationPreferenceTypeNotEmail() {
return this.communicationPreferences.filter((e) => e.type !== 'EMAIL')
},
},
我的測驗規格:
it('should filter communication preferences by TYPE', () => {})
uj5u.com熱心網友回復:
您的問題僅包括模板中帶有CommunicationPreference組件的部分,因此很難說出模板的其余部分會是什么樣子。但我認為這可能會對您有所幫助:
import { mount } from '@vue/test-utils'
import Component from './path/to/Component'
const mockedCommunicationPreferencies = [
{
//...,
type: 'EMAIL',
},
//...
{
//...,
type: 'NOT-EMAIL',
}
]
it('should filter communication preferencies by TYPE', () => {
let component = mount(Component)
component.setData({ communicationPreferences: mockedCommunicationPreferences })
const emailCommunicationPreferences = component.vm.communicationPreferenceTypeEmail
const nonEmailCommunicationPreferences = component.vm.communicationPreferenceTypeNotEmail
expect(emailCommunicationPreferencies.every(cp => cp.type === 'EMAIL')).toBeTruthy()
expect(nonEmailCommunicationPreferencies.every(cp => cp.type !== 'EMAIL')).toBeTruthy()
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/457270.html
標籤:javascript Vue.js 单元测试
上一篇:如何修補在函式外部實體化的物件以在每個測驗python中重用
下一篇:模塊模式變數在測驗中回傳未定義?
