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

Add with-mocha example #51

Closed
wants to merge 3 commits into from
Closed

Add with-mocha example #51

wants to merge 3 commits into from

Conversation

msutkowski
Copy link
Member

Changes

Example checklist

  • I've followed the Contribution guidelines.
  • I've verified that all added tests pass by running npm test.
  • I've included only the necessary minimum setup to showcase the example.
  • I've added a README.md file to the root directory of my example.

@msutkowski
Copy link
Member Author

I left this pretty close to the example issue and solution. I think this is general enough to show as an example for mocha users and explains the caveats (no parallel mode support as of now)

examples/with-mocha/README.md Outdated Show resolved Hide resolved
examples/with-mocha/package.json Show resolved Hide resolved
timdeschryver
timdeschryver previously approved these changes Mar 15, 2021

// Support fetch in a node env. Requires the localstorage polyfill
require('isomorphic-fetch')
require('localstorage-polyfill')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the localstorage-polyfill if we use whatwg-fetch instead?

I find it the less things our examples have, the more straightforward they are to follow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kettanaito localstorage would still need to be mocked or polyfilled here using whatwg-fetch. I can just include a mock if you think it's more transparent than including this polyfill or a mock lib, just let me know :)

afterEach(() => {
// Reset any modified handlers and cleanup tests
server.resetHandlers()
cleanup()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't RTL call cleanup automatically? Does that work only in Jest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, but unfortunately, that's not the case here. If you add console.log(screen.debug()) to the last test in Child, you'll see that it stacks components and the tests will fail.

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for preparing this example, @msutkowski! I've left a few comments.

@msutkowski
Copy link
Member Author

@kettanaito Updated, but left the localstorage polyfill in place per the comment. If you want me to include a manual mock for this, just let me know :)

@kettanaito
Copy link
Member

Thanks for all the work on this, @msutkowski! As I'm updating the examples, I think I will drop this one. The usage with mocha is rather straightforward, and mocha+react is a bit too complex to feature as a standalone example.

@kettanaito kettanaito closed this Oct 18, 2023
@kettanaito kettanaito deleted the add-mocha-example branch October 18, 2023 09:45
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants