spring-media / jest-nock

Automate request traffic recording and replay for tests.
MIT License
9 stars 6 forks source link

Why the `.nock` suffix? #6

Open piranna opened 5 years ago

piranna commented 5 years ago

https://github.com/spring-media/jest-nock/blob/bfe7d53563109cf5db514491ebcf884c24bb0185/index.js#L146-L149

Why are nocked functions set as new .nock ones instead of replace the original ones? This way capture would be done for all the tests... I think it makes sense to at least give the option to replace all tests functions with that. Also, maybe it would be possible to do the monkey patching automatically instead of by adding a setup file?

kommander commented 5 years ago

It was meant to mark tests which use the nock feature explicitly. You are right that each test function could record/replay by default. Only reason I could think of was migrating an existing test suite, which makes real network calls to dev/mock APIs, which was a real use case. In that scenario not all tests should use nocks, only additional ones and then existing ones were migrated. So to allow that, an --explicit-nocked switch via CLI or something along those lines would be good. May be something for a 0.2 version.