sp-dev-fx-controls-react icon indicating copy to clipboard operation
sp-dev-fx-controls-react copied to clipboard

Cannot find module '@ms/odsp-core-bundle' or its corresponding type declarations while testing

Open Krugerro opened this issue 2 years ago • 3 comments

Category

[ ] Enhancement

[ x] Bug

[ ] Question

Version

Please specify what version of the library you are using: [ 3.14.0 but same on 3.15.0 ]

Expected / Desired Behavior / Question

I am using FileTypeIcon component. It works as expected but error arises when performing tests using jest and react-testing-library. I got error: Cannot find module '@ms/odsp-core-bundle' from 'node_modules/@pnp/spfx-controls-react/node_modules/@microsoft/sp-core-library/lib-commonjs/SPExperiment.js' and when opening SPExperiment.js file I got: image

Observed Behavior

Test should go smoothly without errors.

Steps to Reproduce

Write test as below (sample)

import { FileTypeIcon, IconType, ImageSize } from "@pnp/spfx-controls-react";
import "@testing-library/jest-dom";
import { render } from "@testing-library/react";
import React from "react";

describe("<FileTypeIcon/>", () => {
  it("renders file type icon", () => {
    render(
      <FileTypeIcon
        type={IconType.image}
        path={"some_url"}
        size={ImageSize.small}
      />
    );
    //some assertions
  });
});

Run test.

Krugerro avatar Sep 12 '23 07:09 Krugerro

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Sep 12 '23 07:09 ghost

Thank you for submitting your first issue to this project.

github-actions[bot] avatar Sep 12 '23 07:09 github-actions[bot]

Hi @Krugerro,

I'm not familiar with those testing libraries but I noticed the same issue if I try to bundle a SPFx solution which uses PnP Controls but without @microsoft/sp-core-library installed.

Is this package installed / loaded when you're running your tests?

michaelmaillot avatar Apr 15 '24 12:04 michaelmaillot

Closing this as no response from the author. Feel free to reopen it if needed.

michaelmaillot avatar Aug 11 '24 13:08 michaelmaillot