Fix tests
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Hamcha 2019-09-20 12:48:57 +02:00
parent 916af31051
commit 9b639a52d1
Signed by: hamcha
GPG Key ID: 44AD3571EB09A39E
4 changed files with 25 additions and 4 deletions

View File

@ -2,7 +2,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "json", "vue", "ts", "tsx"],
transform: {
"^.+\\.vue$": "vue-jest",
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$":
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2|webp)$":
"jest-transform-stub",
"^.+\\.tsx?$": "ts-jest"
},

View File

@ -3,3 +3,4 @@ export * from "./MockPeer";
export * from "./MockHelper";
export * from "./EventHook";
export * from "./IDBShim";
export * from "./sync-utils";

View File

@ -0,0 +1,5 @@
export function seconds(ms: number): Promise<void> {
return new Promise(resolve => {
setTimeout(resolve, ms * 1000);
});
}

View File

@ -1,5 +1,7 @@
import CardPicker from "@/components/DeckBuilder/CardPicker.vue";
import { shallowMount } from "@vue/test-utils";
import CardImage from "@/components/Cards/CardImage.vue";
import { shallowMount, mount } from "@vue/test-utils";
import { seconds } from "@/testing";
// Generate 10 test cards
const testCards = new Array(10)
@ -8,8 +10,8 @@ const testCards = new Array(10)
const testSlots = testCards.map(c => ({ data: c, limit: 3, howmany: 1 }));
describe("components/DeckBuilder/CardPicker", () => {
test("CardPicker correctly creates images for each card", () => {
const wrapper = shallowMount(CardPicker, {
test("CardPicker correctly instances images for each card", () => {
const wrapper = mount(CardPicker, {
propsData: {
rows: 2,
columns: 5,
@ -20,6 +22,19 @@ describe("components/DeckBuilder/CardPicker", () => {
expect(cards.contains("img")).toBe(true);
});
test("CardImage correctly resolves to an URL after a while", async () => {
const wrapper = mount(CardImage, {
propsData: {
id: "sb1"
}
});
let src = wrapper.attributes("src");
expect(src).toBe(""); // Should be placeholder but it gets stubbed
await seconds(0.5);
src = wrapper.attributes("src");
expect(src).toMatch(/^https?:|^blob:/);
});
test("CardPicker correctly aligns items in a grid", () => {
const wrapper = shallowMount(CardPicker, {
propsData: {