-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Pass Jest done callback to testMethod #3853
Pass Jest done callback to testMethod #3853
Conversation
addons/storyshots/storyshots-core/src/api/snapshotsTestsTemplate.js
Outdated
Show resolved
Hide resolved
1b24a89
to
f489d48
Compare
Hello again ... I finally made some time to update and finish this PR. Added tests, updated to use the new API of the |
So far the only check failing is the one at Better Code Hub ... I tried to access it but it says only organization members can access the code ... |
I'm going to rename the option to avoid conflicts with |
f489d48
to
ae450a3
Compare
Codecov Report
@@ Coverage Diff @@
## master #3853 +/- ##
==========================================
+ Coverage 40.59% 40.74% +0.15%
==========================================
Files 483 484 +1
Lines 5747 5760 +13
Branches 770 771 +1
==========================================
+ Hits 2333 2347 +14
+ Misses 3042 3041 -1
Partials 372 372
Continue to review full report at Codecov.
|
ae450a3
to
917d745
Compare
@igor-dv can you take a look at this again please ? |
Don't worry about Better Code Hub |
Let's get @igor-dv's approval too |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call it just async
?
|
||
// finally mark test as done | ||
done(); | ||
}, TIMEOUT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be flacky
|
||
### StoryShots for async rendered components | ||
|
||
You can make use of [Jest done callback](https://jestjs.io/docs/en/asynchronous) to test components that render asynchronously. This callback is passed as param to test method passed to `initStoryshots(...)` when the `asyncJest` option is given as true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this parameter should be listed in the Options
sections also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just updated this PR with changes you requested @igor-dv .
By the way, I've used just async
first but then I've opted for asyncJest
to avoid issues with syntax highlightings that were assuming it was the async
ES keyword
}) | ||
|
||
|
||
// file: StoryShots.test.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please separate each example file to a its own block
917d745
to
721131f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Can you please merge from master, to pass CI?
721131f
to
bb76bfd
Compare
@igor-dv the branch is now up-to-date ... the CircleCI is apparently failing because |
Thx for accepting this PR ladies and gentlemen |
Note that Not saying that you shouldn't expose a |
Thx and wow! I haven't heard of |
"legacy" might be too strong. It's probably never going away because of old code bases, and it's a nice way to programatically fail a test. But most of the time doing If you work with a callback API I would still use promises, maybe like this: test('some api with cb pattern', async () => {
const result = await new Promise((resolve, reject) => {
callApiWithCallback((err, res) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
});
expect(result).toBeSomething();
}); Or use something like https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original. So yeah, |
I'd like to submit a PR to mention about using promise instead of Anyway, for people that might be worry, I can tell you that you still get a full test run with failing assertions and |
You can wait a millisecond using |
Issue: NO ISSUE
What I did
I added the Jest done callback to be passed to the testMethod in StoryShot addon. Also updated the addon's README.
How to test
Is this testable with Jest or Chromatic screenshots?
I don't think so
Does this need a new example in the kitchen sink apps?
I don't think so
Does this need an update to the documentation?
I updated the StoryShot addon README with usage example.
If your answer is yes to any of these, please make sure to include it in your PR.