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

How to mock the PeoplePicker control using Jest and React testing Library.

Open BasantPandey opened this issue 2 years ago • 4 comments

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the documentation to see if your question is already addressed there. This will help us ensure our documentation is up to date.

Category

[ ] Enhancement

[ ] Bug

[x] Question

Version

Please specify what version of the library you are using: [ 3.14.0 ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

Getting this error :

Cannot find module 'ControlStrings' from 'PeoplePickerComponent.js' and also getting this issue.

  1. this.props.webPartContext.pageContext.site.absoluteUrl
  2. this.props.webPartContext.pageContext.site.absoluteUrl

Using

  1. React testing library with Jest

Please suggest if you have any idea.

Observed Behavior

If you are reporting an issue please describe the behavior you expected to occur when performing the action. If you are making a suggestion or asking a question delete this section.

Steps to Reproduce

If you are reporting an issue please describe the steps to reproduce the bug in sufficient detail to allow testing. If you are making a suggestion or asking a question delete this section.

Submission Guidelines

Delete this section after reading

  • All suggestions, questions and issues are welcome, please let us know what's on your mind.
  • Remember to include sufficient details and context.
  • If you have multiple suggestions, questions, or bugs please submit them in separate issues so we can track resolution.

Thanks!

BasantPandey avatar Sep 20 '23 15:09 BasantPandey

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

ghost avatar Sep 20 '23 15:09 ghost

Thank you for submitting your first issue to this project.

github-actions[bot] avatar Sep 20 '23 15:09 github-actions[bot]

Hi @BasantPandey,

I don't have experience with Jest, but can you give us a code snippet (from your test case) that includes the PnP Controls please?

Edit: it could be useful if someone has much experience with testing tools.

michaelmaillot avatar Sep 25 '23 11:09 michaelmaillot

Hi @michaelmaillot I hope you are doing well. I'm sorry for not getting back to you sooner.

  1. This is the error. image
  2. When I try to mock this using the jest.comfig.json file. image
  3. Open the command prompt and run this command .\node_modules\.bin\jest --config ./config/jest.config.json
  4. Here is a project repo https://github.com/BasantPandey/SPFxWithRTL

BasantPandey avatar Oct 07 '23 06:10 BasantPandey