Open lukeapage opened 5 years ago
jest captures the stack on calling toMatchInlineSnapshot and then matches up the ast based on the callsite column and line.
There are some challenges doing this with cypress:
so, I think a workable approach would be to use the test title and the order of the calls to determine the right call to make. This is more limiting, but in practice I can't think of any problems - for instance if you have a forEach around the test and dynamically create the test - this currently works in jest, but it opts out if the same call site is used more than twice - so in practice it only works if the dynamic test name is created only once. The same for abstracted functions - they work but only if called once. So I do not think the limitations are too bad - it would work for me.
Now that https://github.com/cypress-io/cypress/pull/4041 is merged, is it technically possible to implement this?
This would be a long awaited feature for us.
Having the assertion separate from the test makes it less likely to be reviewed and makes it harder to align assertion value and test.
Describe the solution you'd like To implement toMatchInlineSnapshot like jest.
Jest implementation: https://github.com/facebook/jest/commit/d3a6a7400a89b857a63d939fc5664ae8a2dfbbb2#diff-5d8368ae467702f37535e03f31a2ed96
It seems doable from a cursory look. I would follow the jest approach, requiring prettier if it’s used. I’m interested in implementing this myself, just raising this in case you have objections or suggestions.