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

docs: runnable example of the for Each test #13428

Merged
merged 35 commits into from
Jan 1, 2023
Merged

Conversation

Jeroendevr
Copy link
Contributor

Hi, Perhaps the documentation is written for (more) experienced programmers or for readers who nicely walked through the tutorial but for past me It would have been helpful to have a runnable example. Therefore my suggested improvements so that one can copy paste it to their editor.

Hi, Perhaps the documentation is written for (more) experienced programmers or for readers who nicely walked through the tutorial but for past me It would have been helpful to have a runnable example. Therefore my suggested improvements so that one can copy paste it to their editor.
Copy link
Contributor

@mrazauskas mrazauskas left a comment

Choose a reason for hiding this comment

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

Thanks. That is good idea.

Please fix docs for all versions and the Next version too.

Also run yarn lint (;

website/versioned_docs/version-29.1/MockFunctions.md Outdated Show resolved Hide resolved
website/versioned_docs/version-29.1/MockFunctions.md Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

Hi @Jeroendevr!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@Jeroendevr
Copy link
Contributor Author

Jeroendevr commented Dec 14, 2022

I will try to adjust to your suggestions, thanks for the heads up about linting. I am no experienced GitHub user so after my edited PR, you should guide me how to apply this to all versions.
As a reminder for myself

  • Merge suggestions

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Jeroendevr and others added 4 commits December 15, 2022 11:02
@mrazauskas
Copy link
Contributor

Thanks. The changes look good, but you have to run Prettier (through lint command).

No sure why you added a note about new PR. All versioned docs can be updated in one go (one PR). Just make the same change in all files from website/versioned_docs. Right now you have pushed only v29.1. Also the same change should be made in docs directory, this is Next version docs.

@Jeroendevr
Copy link
Contributor Author

Thanks for pointing out the different docs locations, and the linting, and the fact that is should be within one PR.
The linting had some errors in the e2e tests but these are for someone else as I haven't touched it.
Thank you for providing constructive feedback as I am completely unfamiliar with the node/TS ecosystem.
Had some challenges to run the Jest package locally already 😎

Copy link
Contributor

@mrazauskas mrazauskas left a comment

Choose a reason for hiding this comment

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

Thanks. I left few more comments.

Some how I was sure that yarn lint runs Prettier as well, but it doesn’t. You should run yarn lint:prettier additionally. It will add one missing space.

By the way, docs/MockFunctions.md file is missing. Same changes should be made there too. The rest you found (;

website/versioned_docs/version-25.x/MockFunctions.md Outdated Show resolved Hide resolved
website/versioned_docs/version-25.x/MockFunctions.md Outdated Show resolved Hide resolved
Comment on lines 80 to 82
// The function was called with a certain `this` context: the `element` object.
expect(someMockFunction.mock.contexts[0]).toBe(element);

Copy link
Contributor

@mrazauskas mrazauskas Dec 16, 2022

Choose a reason for hiding this comment

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

Hm.. I guess these are accidental changes. Jest v25 does not have mock.contexts it was introduced recently. That is why it appears only in the docs of later versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah my bad. Glad you paid good attention to it.

@@ -17,41 +17,49 @@ function forEach(items, callback) {
callback(items[index]);
}
}
module.exports = forEach;
Copy link
Contributor

Choose a reason for hiding this comment

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

One more thought. What about using ESM syntax here? The examples below written in ESM: https://jestjs.io/docs/next/mock-functions#mocking-modules

Copy link
Contributor Author

@Jeroendevr Jeroendevr Dec 16, 2022

Choose a reason for hiding this comment

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

ESM syntax is then export forEach; ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is:

export function forEach(items, callback) {
  // etc ...

And instead of const forEach = require('./foreach');:

import {forEach} from './forEach';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I thought there were two ways to export a module.
One as you describe it. Add export before the function declaration and one where you can group all the functions, classes you want to export together (for example at the bottom)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok if v25 is acceptable I'll change the others as well. Thanks for learning on the job.

@Jeroendevr
Copy link
Contributor Author

Ok thanks for the feedback, added the two empty lines. Also updated along all the versions. Hopefully done it well. 🫣🤗

docs/MockFunctions.md Outdated Show resolved Hide resolved
@mrazauskas
Copy link
Contributor

Thanks. All looks good to me.

Now we have to wait for the maintainer to take a look.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

great stuff, thanks!

@SimenB SimenB changed the title Runnable example of the for Each test docs: runnable example of the for Each test Jan 1, 2023
@SimenB SimenB merged commit 24d5d04 into jestjs:main Jan 1, 2023
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants