Skip to content

Can't start test in Jest #2

@ilbertt

Description

@ilbertt

I'm trying to use LightIC with Jest.

I wrote this simple test:

import { Actor } from "@dfinity/agent";
import { Principal } from "@dfinity/principal";
import { TestContext } from "lightic";

const context = new TestContext();
let actor: Actor;

describe("Canister", () => {
  beforeAll(async () => {
    // @ts-ignore
    const canister = await context.deploy('./.dfx/local/canisters/backend/backend.wasm');
    console.log(canister)

    const caller = Principal.anonymous();

    // @ts-ignore
    actor = Actor.createActor(canister.getIdlBuilder(), {
      // @ts-ignore
      agent: context.getAgent(caller),
      canisterId: canister.get_id()
    })
  });

  it("is true", () => {
    console.log(actor);
    expect(true).toBe(true);
  });
});

Run it simply with:

npx jest

But I got this error:

FAIL  tests/integration/canister.test.ts
  Canister
    ✕ is true (1 ms)

  ● Canister › is true

    TypeError: WebAssembly.Module.customSections(): Argument 0 must be a WebAssembly.Module

      at WasmCanister.get_candid (node_modules/lightic/src/wasm_canister.ts:270:42)
      at async WasmCanister.install_module_candid (node_modules/lightic/src/wasm_canister.ts:116:20)
      at async ReplicaContext.install_canister (node_modules/lightic/src/replica_context.ts:198:5)
      at async TestContext.deploy (node_modules/lightic/src/test_context.ts:49:20)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.083 s

The ./.dfx/local/canisters/backend/backend.wasm file exists.

(Note that I also had to use @ts-ignore, which I think is due to different versions of the @dfinity/* packages)

Context:

  • node: v16.14.1
  • lightic: 0.3.1
  • jest: 29.6.1
  • @dfinity/*: 0.15.1
  • dfx: 0.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions