Skip to content

Unit testing typescript SPFx web part using jest #13

@rahil1998

Description

@rahil1998

Question:

How do you unit test the SPFx web part, written in typescript (react), that uses @pnp Call to communicate with SharePoint?
How to mock PNP call or how to make ignorable for the test case.

below I mentions the error related to PNP

E:\Projects\Unit Testing\SPFx-unit-testing\node_modules\@pnp\logging\index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from "./logger";
                                                                                      ^^^^^^

    SyntaxError: Unexpected token export

      3 | import { IPnpSpCrudProps } from './IPnpSpCrudProps';
      4 | import { escape } from '@microsoft/sp-lodash-subset';
    > 5 | require("@pnp/logging");
        | ^
      6 | require("@pnp/common");
      7 | require("@pnp/odata");
      8 | import { sp } from "@pnp/sp/presets/all";

I have configured the unit test and sample test execute successfully (without PNP)
SPFx-unit-testing

Let me know your thoughts
@andrewconnell
Thanks

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