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

TypeError: resources must be an instance of ResourceLoader #3717

Closed
Shramkoweb opened this issue May 16, 2024 · 3 comments
Closed

TypeError: resources must be an instance of ResourceLoader #3717

Shramkoweb opened this issue May 16, 2024 · 3 comments

Comments

@Shramkoweb
Copy link

Shramkoweb commented May 16, 2024

Basic info:

  • Node.js version: v20.12.2
  • jsdom version: ^24.0.0

I am trying to update jsdom from 20 to 24, and get an error:
TypeError: resources must be an instance of ResourceLoader

Minimal reproduction case

I used config same like in your documentation , and this is worked before .

import { TestEnvironment } from 'jest-environment-jsdom';
import { ResourceLoader } from 'jsdom';

class CustomResourceLoader extends ResourceLoader {
  fetch(url, options) {
    if (url === 'https://mock.local/success.js') {
      return Promise.resolve(Buffer.from(''));
    }

    if (url === 'https://mock.local/fail.js') {
      return Promise.reject();
    }

    return super.fetch(url, options);
  }
}

class CustomJSDOMEnvironment extends TestEnvironment {
  constructor(config, options) {
    super(
      {
        ...config,
        projectConfig: {
          ...config.projectConfig,
          testEnvironmentOptions: {
            ...config.projectConfig.testEnvironmentOptions,
            resources: new CustomResourceLoader(),
          },
        },
      },
      options
    );
  }
}

export default CustomJSDOMEnvironment;

It reproduces in 21, 22, 23, and 24 versions.

@Shramkoweb
Copy link
Author

@SimenB maybe it relates to jestjs/jest#8701 (comment), but it desn't work

@domenic
Copy link
Member

domenic commented May 17, 2024

Unfortunately we cannot help debug issues with third party packages like jest-environment-jsdom. If you can rewrite this to follow the issue template and produce a file using only jsdom which we can run using node test.js, we can reopen.

@domenic domenic closed this as completed May 17, 2024
@SimenB
Copy link
Contributor

SimenB commented May 17, 2024

You'll need to match up jsdom version with jest-environment-jsdom. See jestjs/jest#14954 (comment) for an example of how to use your own version (e.g. 24)

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

3 participants