I’ve looked into this and had success with ts-patch instead of ttypescript:
npm uninstall ttypescript
npm i -D ts-patch
on package.json change the compiler:
"jest": {
"globals": {
"ts-jest": {
"compiler": "ts-patch/compiler"
}
},
I’ll list here the rest of the steps I took to make it work locally, you may not need all of these but they will be patched into the testing guide later:
- Adjust import path:
import AddItemRpc from "./rpc-add-item"; - Use
@jest/globalsinstead of@types/jest:
npm install --save-dev @jest/globals
- Add needed imports to
rpc-add-item.test.ts:
import { describe, expect, beforeEach, test } from '@jest/globals';
import 'jest'
- If you have strict type-checking enabled:
On rpc-add-item.test.ts:
let mockCtx: any, mockLogger: any, mockNk: any, mockLoggerError: any, mockNkStorageRead: any, mockNkStorageWrite: any, mockStorageWriteAck: any;
On rpc-add-item.ts:
type Inventory = {
[key: string]: any;
};
const AddItemRpc = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string | null): string {
...
let inventory: Inventory = {};
Let me know if that works for you.