-
-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
I have a very simple test case like this:
requestBody := map[string]string{
"email": "[email protected]",
"password": "password13",
}
body, err := json.Marshal(requestBody)
require.NoError(t, err)
req := httptest.NewRequest(http.MethodPost, "/sign-in", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
recorder := httptest.NewRecorder()
requestDump, err := httputil.DumpRequest(req, true)
require.NoError(t, err)
snaps.MatchSnapshot(t, string(requestDump))
snaps.MatchStandaloneSnapshot(t, string(requestDump))The gist is that I create a new request and dump the request in standard text representation. That representation is saved as a snapshot. I've noticed that there's difference between how MatchSnapshot prints the diff vs how MatchStandaloneSnapshot does it.
Here's an example output (in both cases, this is the only snapshot available in a file):
--- FAIL: TestHandleSignIn (0.00s)
--- FAIL: TestHandleSignIn/should_return_201_and_token_when_sign_in_succeeds (0.00s)
auth_sign_in_test.go:42:
- Snapshot - 5
+ Received + 5
- POST /sign-in HTTP/1.1
- Host: example.com
- Content-Type: application/json
-
- {"email":"[email protected]","password":"password12"}
+ POST /sign-in HTTP/1.1
+ Host: example.com
+ Content-Type: application/json
+
+ {"email":"[email protected]","password":"password13"}
at __snapshots__/auth_sign_in_test.snap:2
auth_sign_in_test.go:43:
- Snapshot - 1
+ Received + 1
Host: example.com
Content-Type: application/json
- {"email":"[email protected]","password":"password12"}
+ {"email":"[email protected]","password":"password13"}
at __snapshots__/TestHandleSignIn_should_return_201_and_token_when_sign_in_succeeds_1.snap:1As you can see the output from MatchStandaloneSnapshot is much better showing only the line that actually changed.
Steps to Reproduce
- Prepare a test like this:
requestBody := map[string]string{
"email": "[email protected]",
"password": "password12",
}
body, err := json.Marshal(requestBody)
require.NoError(t, err)
req := httptest.NewRequest(http.MethodPost, "/sign-in", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
recorder := httptest.NewRecorder()
requestDump, err := httputil.DumpRequest(req, true)
require.NoError(t, err)
snaps.MatchSnapshot(t, string(requestDump))
snaps.MatchStandaloneSnapshot(t, string(requestDump))go test ./...- Change
requestBody(e.g. add a character to one of the values). go test ./...
Expected Behavior
Both snapshots should only show the line that changed.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working