Replies: 1 comment 6 replies
-
Hi @dafurman, thanks for bringing this up! It's a good question, and to be honest we don't quite remember why we chose what we did. We even discussed a few weeks ago that it seemed like it would have been better to have preview values take from the I guess one thing that comes to mind is that it may seem surprising for previews to seem subtly broken if they take from the We'll discuss a bit more about changing the behavior, but please do share any other information you have on this or if anyone else wants to chime in! |
Beta Was this translation helpful? Give feedback.
-
Right now, tests spit out a handy error about a dependency being unmocked:

However, previews aren't equipped with the same capability, and they default to a live value.
I don't know that this is necessarily an "issue", but I wanted to open up some discussion around this. I feel like neither previews nor tests should default to live values, and that leaving them unspecified when they end up getting used should be considered a developer error, to ensure we're deliberate and thoughtful about dependencies that get used.
In the documentation here, there seems to be a similar sentiment:
I don't know that I agree with the second sentence here though:
Just like with how you've described exhaustive dependencies in tests here, I really like the idea of being explicit about which dependencies are actually getting used in previews, so that devs aren't unknowingly depending on default mocks, or on live data that could change out from under them (or hit APIs and cost money! 😱)
However...I don't really know how this could be done today.

XCTFail
isn't an option for previews, and previews don't play nicely withfatalError
as a way to indicate an error, so I don't think that approach would be great. These popups can be pretty annoying:We could try doing something like creating runtime warnings, but I'm pretty sure if we're not fatalErroring, we'd still need a basic mock implementation to return in order to compile. Fortunately it looks like
unimplemented()
from XCTestDynamicOverlay does something similar to support placeholders already, so maybe it could just be a matter of updating thoseunimplemented()
functions to error more nicely in previews?Maybe we're simply stuck here without better error tooling in previews, but I'm curious to hear others' thoughts on this!
As a partial solution, it almost seems like we should delete this default value of previews defaulting to live. I'm curious to hear the motivation behind this.
Beta Was this translation helpful? Give feedback.
All reactions