Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: setImmediate is not defined #23

Closed
railsfactory-vishnuroshan opened this issue Jan 4, 2022 · 4 comments
Closed

ReferenceError: setImmediate is not defined #23

railsfactory-vishnuroshan opened this issue Jan 4, 2022 · 4 comments

Comments

@railsfactory-vishnuroshan

I am using next.js project with typescript.

I am facing this issue when jest tries to run the mock file

ReferenceError: setImmediate is not defined

      12 | }
      13 |
    > 14 | import { Client } from '@elastic/elasticsearch';
         | ^
      15 | import Mock from '@elastic/elasticsearch-mock';
      16 |
      17 | const mock = new Mock();

      at Object.<anonymous> (node_modules/@elastic/elasticsearch/lib/Helpers.js:27:30)
      at Object.<anonymous> (node_modules/@elastic/elasticsearch/index.js:29:17)
      at Object.<anonymous> (__mocks__/elasticsearch.ts:14:1)

in the file __mocks__/elasticsearch.ts

import { Client } from '@elastic/elasticsearch';
import Mock from '@elastic/elasticsearch-mock';

const mock = new Mock();
const client = new Client({
  node: 'http://localhost:9200',
  Connection: mock.getConnection(),
});

mock.add(
  {
    method: 'GET',
    path: '/',
  },
  () => {
    return { status: 'ok' };
  }
);

client.info(console.log);

@yidah
Copy link

yidah commented Jan 10, 2022

Hi,

I am having the same problem as @railsfactory-vishnuroshan in a node JS project, same configuration, same error. Has somebody solved this error?

Thanks for your help.

@delvedor
Copy link
Member

Hello! Very likely Jest is doing something weird behind the scenes and breaks the client code.
See jestjs/jest#2549.

@railsfactory-sivamanikandan

Hi All,
This issue is due to test environment, if you are using --env=jsdom you will get this issue.
Please try to remove this --env=jsdom or use --env=node

@railsfactory-vishnuroshan
Copy link
Author

The solution given by @railsfactory-sivamanikandan worked. I am closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants