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

Jest test runner fails when trying to test ajax.fetch module #8

Closed
seanttaylor opened this issue Jun 26, 2022 · 3 comments
Closed

Jest test runner fails when trying to test ajax.fetch module #8

seanttaylor opened this issue Jun 26, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@seanttaylor
Copy link
Owner

The following unit test:

import ajax from '../../src/sandbox-controller/ajax/index.js';

const { fetch } = ajax;

/**
 * This test suite verfies the the custom {Fetch} interface. (Actual network fetching will be covered in an integration test.)
 */
describe('Ajax', () => {
    test('Should be able to take a configuration for an HTTP request', async () => {
        const data = await fetch({ url: 'http://httpbin.org/json' });
        console.log({ data });
        expect(data).toBeTruthy();
    });
});

fails with the error messsage:

 /workspaces/sandbox-poc/node_modules/node-fetch/src/index.js:9
    import http from 'node:http';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module
@seanttaylor seanttaylor added the bug Something isn't working label Jun 26, 2022
@seanttaylor
Copy link
Owner Author

Looks like any test that covers node-fetch fails with the same error above ☝️

@seanttaylor
Copy link
Owner Author

seanttaylor commented Jun 26, 2022

Okay. This is a known issue with the latest versions of Jest not supporting ES modules. See here.

@seanttaylor
Copy link
Owner Author

Ended up downgrading to the previous major node-fetch version 2.6.1. This fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant