I am trying to use Jest.js to test some typescript code I wrote. I am getting an error "Error: Do not import @jest/globals
outside of the Jest test environment" but I thought I was in a jest testing environment. Here is my code:
import {NewMarketContractRequest, NewContractReponse, MarketSalesDataReply, MessageResonse} from '../models';
import {describe, expect, test} from '@jest/globals';
import {deployNewMarketContract} from '../market-contract-lib';
describe('deployNewMarketContract', () => {
it('should deploy a new market contract', async () => {
var request: NewMarketContractRequest = {
contractId: 'market3.testnet',
ownerAccount: 'market3.testnet',
ftTokenIds: [],
chainId: 'testnet',
toJSON: () => {return "";},
toObject: () => { return new Object();}
};
const response = await deployNewMarketContract(request);
expect(response.id).toBeDefined();
expect(response.createdTime).toBeDefined();
expect(response.chainId).toBeDefined();
expect(response.transactionHash).toBeDefined();
});
});
And when I run "npm test" this is what I get:
Error: Do not import `@jest/globals` outside of the Jest test environment
at Object.<anonymous> (C:\s\keypom-api\node_modules\@jest\globals\build\index.js:12:7)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Function.Module._load (node:internal/modules/cjs/loader:930:12)
at Module.require (node:internal/modules/cjs/loader:1113:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\s\keypom-api\src\__tests__\market-contract-tests.ts:2:1)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Function.Module._load (node:internal/modules/cjs/loader:930:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
This test file is the only one that references jest at all so the error message doesn't even seem correct to me.