The expect(request.queryParams.by).to.equal(this.by + 'sdfdg'); should not pass the test because the query param (request.queryParams.by) is equal to ‘gender’. But the test somehow still passed…
I would guess that the test is finishing before your expectation actually evaluates. To be sure we’d need to know more about how your <Patients::Stats> component is doing the data fetching.
This is just a simple fetch in the components constructor and fetching the '/patients/stats' endpoint with the query param 'by' what I pass to the component as an argument. In this case it is look like this: '/patients/stats?by=gender'. This should return a JSON object like in the example.
Right, so the fetch is running asynchronously and there’s nothing to make the render or the test wait for it to finish before moving on.
The simplest change to fix your test is probably to use something like waitFor to wait until your content appears in the DOM. You’d do this after await render().
That way the test won’t end until after your component has had a chance to actually run the whole fetch, which should cause the side-effect of hitting your expectation.
The waitFor is not helped, because the problem is I don’t get back this data from this endpoint. When I comment out expect(request.queryParams.by).to.equal(this.by + 'sdfdg'); this line I got back the data but I don’t how to check the request param.