Skip to content

Snapshot testing is not working #2127

@alenaksu

Description

@alenaksu

As in the title, snapshot testing is not working, it throws the following error

Failed to fetch dynamically imported module: data:text/package.json?wds-javascript;charset=utf-8,...

Test example:

it('should not throw',() => {
    const el = await fixture(
        html`<my-custom-element></my-custom-element>`
    );
    expect(el).shadowDom.to.equalSnapshot();
});

Digging a little bit, It seems that the framework tries to dynamically import the snapshot here, but that file is subject to various transformations, especially by transformModuleImportsPlugin, at the end the import specifier changes from data:text/javascript... to data:text/package.json?wds-javascript....

I'm not sure though if there is something wrong in my configuration:

export default {
    files: ['src/**/*.spec.ts'],
    plugins: [
        esbuildPlugin({ ts: true }),
        importMapsPlugin({
            inject: {
                exclude: ['node_modules'],
                importMap: {
                    imports: {
                        '/src/lib/api.ts': '/__mocks__/lib/api.ts',
                    },
                },
            },
        }),
    ],
    nodeResolve: true
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions