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 for price is set up correctly.
displays the initial price
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!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.