私の以下のテストは機能します、
let output = mount(story);
expect(output.text()).toContain('Superman');
しかし、バットマンとスパイダーマンを通過させる必要があります。output.text()に-> ['Superman'、 'Batman'、 'Spiderman']があるかどうかを確認する必要があります。
でそれを行うことはできません
expect(output.text()).toContain(['Superman','Batman','Spiderman']);
output.text()willlには、「スーパーマンが最高」または「スパイダーマンが最高」が含まれます
の代わりに独自のマッチャーを追加できますtoContain
。
expect.extend({
toContainHero(text) {
let pass = false;
const heroes = ['Superman','Batman','Spiderman'];
heroes.forEach((hero) => {
pass = text.indexOf(hero) !== -1;
})
if (pass) {
return {
message: () =>
`expected hero to be found`,
pass: true,
};
} else {
return {
message: () => `expected hero to be not found`,
pass: false,
};
}
},
});
そして、次のことを行います。
expect(output.text()).toContainHero();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加