Thanks for pointing this out, I think I just did a poor job of explaining it so Iβll try to rewrite this to make it clearer.
This middle section is mid-refactor which is part of the trouble. Because I'm refactoring the code by extracting the fetch logic into a store, the tests for CallbackComponentshould no longer care about fetch at all.
The test displays the initial price that doesnβt care so much about how the data is retrieved, it just cares that the Svelte subscription for price is set up correctly.
But the test with the set AND the fetch stub is a half-way house between the old version and the new version. The final section of this post removes the need to stub window.fetch by instead stubbing out fetchPrice instead. That is a good thing because the tests for CallbackComponent then have no knowledge of how fetchPrice works (i.e. by calling window.fetch, just like the component itself.
Iβm still not sure if Iβm doing a good job of describing this--let me know if this has helped!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for pointing this out, I think I just did a poor job of explaining it so Iβll try to rewrite this to make it clearer.
This middle section is mid-refactor which is part of the trouble. Because I'm refactoring the code by extracting the fetch logic into a store, the tests for
CallbackComponent
should no longer care about fetch at all.The test
displays the initial price
that doesnβt care so much about how the data is retrieved, it just cares that the Svelte subscription forprice
is set up correctly.But the test with the set AND the fetch stub is a half-way house between the old version and the new version. The final section of this post removes the need to stub
window.fetch
by instead stubbing outfetchPrice
instead. That is a good thing because the tests forCallbackComponent
then have no knowledge of howfetchPrice
works (i.e. by callingwindow.fetch
, just like the component itself.Iβm still not sure if Iβm doing a good job of describing this--let me know if this has helped!