-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(snapshot): concatenate name of test and snapshot #4460
Conversation
I find the context of the test name and the snapshot name very useful in cases where you have multiple different Meanwhile I also added the option to add a testName to `toThrowErrorMatchingSnapshot`. I inspired from jestjs#2094, but couldn't really find back where the exact tests are I need to change for this to work. Let me know if I'm on the correct path
@@ -126,8 +124,6 @@ const toThrowErrorMatchingSnapshot = function(received: any, expected: void) { | |||
); | |||
} | |||
|
|||
ensureNoExpected(expected, '.toThrowErrorMatchingSnapshot'); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why it is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because expected
now is the testName
72be344
to
923e9eb
Compare
I have a bunch of failing tests running locally that seem to be unrelated to this change, so if someone can take a look in what causes these failures locally, as well as on the CI
|
@Haroenv Your new test fails on appveyor, could you take a look? |
@SimenB, I don't understand how the test can fail on appVeyor but not on other platforms. It doesn't seem to be anything windows-specific? |
If you still have issues locally, try rebasing on master, and doing I do agree it seems odd the test should only fail on appveyor, though. Maybe the generated filename somehow is messed up? I'd be interested in a fresh CI run, so if you could push a rebased PR, that'd be great. Restarting the node 6 build on circle didn't help... |
Tests have always passed on my end |
@SimenB tests pass now, but node 4 fails from the merge 🤔 |
Codecov Report
@@ Coverage Diff @@
## master #4460 +/- ##
==========================================
+ Coverage 57.12% 57.13% +<.01%
==========================================
Files 194 194
Lines 6566 6565 -1
Branches 3 3
==========================================
Hits 3751 3751
+ Misses 2815 2814 -1
Continue to review full report at Codecov.
|
Wait, can somebody explain this change to me? I don't get it. |
My idea was that if you're adding a custom snapshot name, it is because you have a lot of them in the same test and want to reference which is the test it actually occurs in. Imagine having a few different cases in which you'll add the same snapshots, then you might want to know which snapshot is for which test. const getData = format => ({
color: 'red',
format,
});
it('works with format true', () => {
const data = getData(true);
expect(Object.keys(data)).toMatchSnapshot('has correct keys');
expect(data.format).toMatchSnapshot('has correct format')
});
it('works with format false', () => {
const data = getData(false);
expect(Object.keys(data)).toMatchSnapshot('has correct keys');
expect(data.format).toMatchSnapshot('has correct format')
}); This is a bit simpler than what you would be doing in real life, but any repeated test cases under similar use cases would make sense. The problem with the implementation right now, is that when you look at the snapshot file, you don't know which test a certain assertion is coming from. Obviously you can work around this before this PR by giving them separate names, but that seems a bit tedious to me. |
Let's do it, although it's a breaking change. |
Thanks :) |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
I find the context of the test name and the snapshot name very useful in cases where you have multiple different
Meanwhile I also added the option to add a testName to
toThrowErrorMatchingSnapshot
.I inspired from #2094, but couldn't really find back where the exact tests are I need to change for this to work.
Let me know if I'm on the correct path
Test plan
I should change the tests for
toMatchSnapshot
, but I'm not totally sure which exactly test this