question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] setupPolly method for jest

See original GitHub issue

Hi team! First of all, thanks a lot for this library, great work 👏

This issue is a proposal and request for comments on adding a setupPolly helper for jest environments. After having a discussion with @offirgolan in https://github.com/Netflix/pollyjs/pull/115#discussion_r222127410 I decided to investigate is it possible to make the same hook support with automated name generation for jest/jasmine environments as the one implemented for Mocha and QUnit in the core of this library.

There are two main differences that I spotted between those two mentioned above and jest/jasmine:

  • this is not commonly used in jest, so access to polly instance should be handled differently
  • there is no “normal” way to acces the current test name in hooks

Trying to address those issues led me to the solution that can be considered hacky, so instead of going with the PR right away, I created setup-polly-jest library as a proof of concept (but it works and covered with tests)

During my investigation I found out that you can get access to the full test name, but to do this, you’ll need a return value from {test,it} call in the test suite.

The solution is to proxy jasmine.Env.it and jasmine.Env.dit methods to get the access to test case instance, get the full name and also hook into before and after hooks of the test case, overriding another jasmine method.

To address the this issue I decided on a little bit different approach, where setupPolly will return context with polly instance as a property (as a bonus, it will also have clearPolly method to disable polly at any moment in the test workflow)

You can find repository here: https://github.com/gribnoysup/setup-polly-jest and it is even published as @gribnoysup/setup-polly-jest so it should be easy for you to test how it works. Repo contains documentation, unit tests and an “integration” test suite that uses the library itself to setup polly in jest test environment

If you think that this approach is acceptable, I’ll be glad to integrate this solution into @pollyjs/corepackage 👍

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gribnoysupcommented, Oct 13, 2018

I updated the repo and now everything is working both for jasmine and jest-jasmine and also matching Mocha/QUnit as close as possible: scoping, naming with folders, setupPolly method API 👍

@offirgolan if you are still okay with the approach, I’m still happy to port it to @pollyjs/core 😸

1reaction
offirgolancommented, Oct 15, 2018

@gribnoysup apologies for the delayed response on this! Thank you again for answering all of my concerns and for taking the time to investigate the jest/jasmine issues further. Looking at the repo, I think this is well executed and would be a super useful addition to the library. Feel free to open up a PR into @pollyjs/core with this and I’ll do whatever I can to help you get this in asap 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

setup-polly-jest - npm
This helper provides a convenient way to use PollyJS (HTTP recording, replaying and stubbing tool) in your Jest/Jasmine tests. Installation.
Read more >
Jest/Enzyme Shallow testing RFC - not firing jest.fn()
I'm trying to test the onChange prop (and the value) of an input on an RFC. On the tests, trying to simulate the...
Read more >
Untitled
Porque o playcenter fechou, Job description approval process, ... Procurement poe setup, Polly's pies orange hours, Intensity of earthquake scale, ...
Read more >
iCloud acknowledgements - Apple Support (GU)
Sergey Petushkov ( Setup-polly-jest ) ... Roman Shtylman ( process ) ... defined in this RFC, under the memorandum of understanding with the...
Read more >
5.xml - jsDelivr
... https://www.jsdelivr.com/package/npm/@gribnoysup/setup-polly-jest monthly ... www.jsdelivr.com/package/npm/@groceristar/data-methods-gsoldserver monthly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found