-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple snapshots for one test, with custom filename disambiguation #70
Comments
Not exactly the same but maybe related to #50 as well. |
I was thinking about this the other day when I tried to do the same thing, so definitely keen for this to be in PixelTest, however I would much prefer it if it was something that PixelTest could figure out itself somehow, with maybe an option for devs to override it if required (although I'd rather leave that until we know it's definitely something that is needed to be added). Initial thoughts are maybe some sort of counter for the amount of times verify is called, which is used in the file name? |
Sure, PixelTest could have a default disambiguator. But it would make the snapshots less useful if they were named |
Good point, how about some sort of context function then? A bit like the BDD scenarios? I just think it might look a bit ugly/hard to read if it's just a long string in the existing verify function. Instead something maybe like:
Btw this just gave me an idea and it's actually already possible to have support for this without needing any changes to PixelTest., using nested functions:
Since PixelTest uses the function name that calls verify, it will use each nested function name. This is obviously gross and we should find a better way but it's definitely possible for now until there's a better way |
I like your suggestion of the context function. |
Though I'm not sure I buy the argument about the
|
Usecase:
Sometimes you want to have multiple snapshots in one test function. Currently this isn't possible as PixelTest only disambiguates the files by filename, function name, and image size. For instance, say you have a view that is configured by 2 enums
Kind
andStatus
. SayKind
has 5 cases, andStatus
has 3 cases. Both conform toCaseIterable
. You want to test all possible configurations (currently 15) by iterating over all cases of both enums. This has the advantage of a. reducing boilerplate test code, and b. automatically adding new snapshots if, eg, a sixth case gets added toKind
.For this to work, PixelTest would need a way to differentiate different snapshots coming from the same test function. I believe the nicest way to do this, would be if you could supply PixelTest with an optional "filenameSuffix" argument. For example, if the
Kind
andStatus
enums both had a developer-friendlydescription
implementation, the call site might look like this:The text was updated successfully, but these errors were encountered: