mocha icon indicating copy to clipboard operation
mocha copied to clipboard

Mocks are skipped if path is not found in JSONPath

Open nixxxon opened this issue 7 months ago • 0 comments

Describe the bug JSONPath returns error if path is not found which breaks the loop in findMockForRequest, skipping the rest of the mocks.

To Reproduce Steps to reproduce the behavior:

  1. Create two POST mocks with different paths and JSONPath.
  2. Send two requests with different json-payload.

My mocks look like this:

srv.Mocha.AddMocks(
	mocha.Post(expect.URLPath("/document/edit")).
		Body(
			expect.JSONPath("document_id", expect.ToEqual(float64(1337))),
		))

srv.Mocha.AddMocks(
	mocha.Post(expect.URLPath("/party/edit")).
		Body(
			expect.JSONPath("party_id", expect.ToEqual(float64(1337))),
		))

Expected behavior The test should succeed, both mocks should be tested. Instead, the second mock is not tested since the second request fails on the first mock. Why is the first mock tested even if the request path does not match with the second request?

Additional context Returning nil instead of err here https://github.com/vitorsalgado/mocha/blob/3.x/expect/jsonpath.go#L22 fixes my tests.

nixxxon avatar Jul 07 '24 12:07 nixxxon