Can't use fuels in jest tests

Hey guys!

I have been trying to create some test for my app using jest, but it fuels imports are failing in test, I am not sure how to fix it, possibly it requires some flag in jestconfig.json or some changes in sdk itself, please help me.

Repo link - https://github.com/compolabs/spark-ts-sdk/blob/v2/tests/creation.test.ts

Test code
wallet.test.ts

import { Wallet } from "fuels";

test("create order", () => {
  console.log("create order");
  const wallet = Wallet.generate();
  console.log(wallet);
});

Error message:

   Cannot find module 'fuels' from 'tests/creation.test.ts'

      3 | import BN from "../src/utils/BN";
      4 | import { nodeUrl, privateKey } from "../src/config";
    > 5 | import { Wallet } from "fuels";
        | ^
      6 | 

Hey @sway! I’m afraid I haven’t been able to recreate your issue. I’ve been able to install fuels in a new project with no additional jest config and run your test: repository.

However I also can’t access your repo, spark-ts-sdk must be private? I’d be happy to take a look if you are able to replicate it in a new repo or give access to that one?

1 Like

My bad, sorry for long reply, now it is public

No problem! So I am seeing:

Test suite failed to run

    src/order.ts:2:49 - error TS2307: Cannot find module './predicates' or its corresponding type declarations.

    2 import { LimitOrderPredicateAbi__factory } from "./predicates";
                                                      ~~~~~~~~~~~~~~
    src/order.ts:3:53 - error TS2307: Cannot find module './predicates/factories/LimitOrderPredicateAbi__factory' or its corresponding type declarations.

    3 import { LimitOrderPredicateAbiConfigurables } from "./predicates/factories/LimitOrderPredicateAbi__factory";

I think there must be some autogenerated predicate factories that haven’t been committed to the branch?