Skip to content

Commit

Permalink
type field test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JPMeehan committed Jun 12, 2024
1 parent f9df5e7 commit e5f71ec
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 5 additions & 3 deletions tests/foundry/common/documents/actor.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ new foundry.documents.BaseActor({});

const baseActor = new foundry.documents.BaseActor({ name: "foo", type: "character" });
expectTypeOf(baseActor.name).toEqualTypeOf<string>();
expectTypeOf(baseActor.effects).toEqualTypeOf<EmbeddedCollection<ActiveEffect, Actor>>();
expectTypeOf(baseActor.effects.get("")).toEqualTypeOf<ActiveEffect | undefined>();
expectTypeOf(baseActor.effects).toEqualTypeOf<
EmbeddedCollection<ActiveEffect.ConfiguredInstance, Actor.ConfiguredInstance>
>();
expectTypeOf(baseActor.effects.get("")).toEqualTypeOf<ActiveEffect.ConfiguredInstance | undefined>();
expectTypeOf(baseActor.effects.get("")!.name).toEqualTypeOf<string>();
expectTypeOf(baseActor.items).toEqualTypeOf<EmbeddedCollection<Item, Actor>>();
expectTypeOf(baseActor.items).toEqualTypeOf<EmbeddedCollection<Item.ConfiguredInstance, Actor.ConfiguredInstance>>();
expectTypeOf(baseActor.items.get("")).toEqualTypeOf<Item | undefined>();
expectTypeOf(baseActor.items.get("")!.img).toEqualTypeOf<string | null | undefined>();
expectTypeOf(baseActor._source.effects[0]!.duration.seconds).toEqualTypeOf<number | null | undefined>();
Expand Down
2 changes: 1 addition & 1 deletion tests/foundry/common/documents/card.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expectTypeOf } from "vitest";
// @ts-expect-error Name is required
new foundry.documents.BaseCard();

const baseCard = new foundry.documents.BaseCard({ name: "foo" });
const baseCard = new foundry.documents.BaseCard({ name: "foo", type: "base" });
expectTypeOf(baseCard._source.faces[0]).toEqualTypeOf<CardFaceData>();

interface OldCardDataSourceData {
Expand Down
4 changes: 1 addition & 3 deletions tests/foundry/common/documents/cards.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { expectTypeOf } from "vitest";
import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.d.mts";
import type { CardDataSource } from "../../../../src/foundry/common/data/data.mjs/cardData.d.mts";
import type { CardFaceDataSource } from "../../../../src/foundry/common/data/data.mjs/cardFaceData.d.mts";

// @ts-expect-error data argument is non-optional
const baseCards = new foundry.documents.BaseCards();
expectTypeOf(baseCards.cards).toEqualTypeOf<EmbeddedCollection<typeof Card, foundry.CardsData>>();
expectTypeOf(baseCards.cards).toEqualTypeOf<EmbeddedCollection<Card.ConfiguredInstance, Cards.ConfiguredInstance>>();
expectTypeOf(baseCards._source.cards[0]).toEqualTypeOf<CardDataSource>();
expectTypeOf(baseCards._source.cards[0].faces[0]).toEqualTypeOf<CardFaceDataSource>();

Expand Down
4 changes: 2 additions & 2 deletions tests/foundry/common/documents/journal-entry-page.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ declare const JEPTypes: foundry.data.fields.TypeDataField.CoreTypeNames<typeof f

expectTypeOf(coreTypeMetadata).toEqualTypeOf<"image" | "pdf" | "text" | "video">();
expectTypeOf(coreTypes).toEqualTypeOf<"image" | "pdf" | "text" | "video">();
expectTypeOf(JEPTypes).toEqualTypeOf<"image" | "pdf" | "text" | "video">();
expectTypeOf(myJournalEntryPage.type).toEqualTypeOf<"image" | "pdf" | "text" | "video">();
expectTypeOf(JEPTypes).toEqualTypeOf<"base" | "image" | "pdf" | "text" | "video">();
expectTypeOf(myJournalEntryPage.type).toEqualTypeOf<"base" | "image" | "pdf" | "text" | "video">();

0 comments on commit e5f71ec

Please sign in to comment.