Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __mocks__/chat-message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {jest} from '@jest/globals';
// @ts-ignore
global.ChatMessage = {
// @ts-ignore
create: jest.fn<() => Promise<null>>().mockResolvedValue(null),
// @ts-ignore
prototype: {
export: () => {return "[] GM\nMessage"}
}
Expand Down
13 changes: 13 additions & 0 deletions __mocks__/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* A fake mock collection for testing purposes.
* Needs to implement the get() and set() functions
*/
export class FakeCollection extends Array {
get size() {
return this.length;
}

get contents() {
return Array.from(this);
}
}
31 changes: 31 additions & 0 deletions __mocks__/const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
// @ts-ignore
global.CONST = {
KEYBINDING_PRECEDENCE: {
// @ts-ignore
NORMAL: 1
},
DOCUMENT_OWNERSHIP_LEVELS: {
// @ts-ignore
INHERIT: -1,
// @ts-ignore
NONE: 0,
// @ts-ignore
LIMITED: 1,
// @ts-ignore
OBSERVER: 2,
// @ts-ignore
OWNER: 3,
},
JOURNAL_ENTRY_PAGE_FORMATS: {
// @ts-ignore
HTML: 1,
// @ts-ignore
MARKDOWN: 2,
},
USER_ROLES: {
// @ts-ignore
NONE: 0,
// @ts-ignore
PLAYER: 1,
// @ts-ignore
TRUSTED: 2,
// @ts-ignore
ASSISTANT: 3,
// @ts-ignore
GAMEMASTER: 4,
}
};
12 changes: 0 additions & 12 deletions __mocks__/draggable.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import {jest} from '@jest/globals';
class DraggableMock{

handlers = {
dragMove: [],
dragUp: []
};

constructor() {
}
}

//@ts-ignore
window.Draggable = DraggableMock;
//@ts-ignore
window.jQuery = jest.fn();
1 change: 1 addition & 0 deletions __mocks__/folder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ts-ignore
global.Folder = {
//@ts-ignore
create: async () => {return true;}
};
42 changes: 42 additions & 0 deletions __mocks__/foundry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
//@ts-ignore
import { jest } from "@jest/globals";

class DraggableMock {
handlers = {
dragMove: [],
dragUp: []
};

static get implementation() {
return DraggableMock;
}

constructor() {
}
}

class ApplicationV2 {
static _maxZ: number;
}

global.foundry = {
//@ts-ignore
applications: {
api: {
//@ts-ignore
ApplicationV2: ApplicationV2,
},
//@ts-ignore
handlebars: {
renderTemplate: (template: string, options?: object) => Promise.resolve(""),
},
ux: {
//@ts-ignore
Draggable: DraggableMock,
}
},
documents: {
collections: {
//@ts-ignore
Journal: {
registerSheet: jest.fn(),
showDialog: async () => {}
},
}
},
//@ts-ignore
utils: {
getRoute: (a: string) => {
Expand Down
15 changes: 6 additions & 9 deletions __mocks__/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* This file mocks the FoundryVTT game global so that it can be used in testing
*/
import { jest } from "@jest/globals";
import { FakeCollection } from "./collection";

//@ts-ignore
const local: Localization = {
lang: "",
Expand Down Expand Up @@ -85,15 +87,7 @@ const game = {
on: jest.fn(),
emit: jest.fn()
},
combats: {
size: 0,
find: jest.fn((v: Function) => {
return v.call(undefined, { started: true });
}),
filter: (v: any) => {
return v.call(undefined, { started: true });
}
},
combats: new FakeCollection(),
modules: {
get: jest.fn()
},
Expand All @@ -119,6 +113,9 @@ const game = {
unshift: (v: any) => {},
contents: () => {
return [user];
},
[Symbol.iterator]: () => {
return [user][Symbol.iterator]();
}
},
scenes: null,
Expand Down
1 change: 0 additions & 1 deletion __mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "./form-application";
import "./game";
import "./handlebars";
import "./hooks";
import "./journal";
import "./journal-sheet";
import "./journal-entry";
import "./merge-object";
Expand Down
2 changes: 1 addition & 1 deletion __mocks__/journal-entry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ts-ignore
global.JournalEntry = {
//getEmbeddedCollection
//@ts-ignore
create: async () => {return {
createEmbeddedDocuments: async () => {}
};}
Expand Down
6 changes: 0 additions & 6 deletions __mocks__/journal.ts

This file was deleted.

Loading