-
Notifications
You must be signed in to change notification settings - Fork 597
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: add mock call history to access request configuration in test #4029
base: main
Are you sure you want to change the base?
Conversation
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 add testing for it?
Yes for sur. I just need times |
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.
Thanks for opening a PR! Can you please add a unit test?
test/mock-agent.js
Outdated
const body = { data: 'value' } | ||
const query = { a: 1 } | ||
url.search = new URLSearchParams(query) | ||
const headers = { authorization: 'Bearer token', 'content-type': 'application/json' } |
Check failure
Code scanning / CodeQL
Hard-coded credentials
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.
lgtm, small comment left
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.
LGTM, left minor comment and should be ready on my end
@mcollina can you take a bit of time to review back this PR ? it would be nice to have this change in the next release 🙏🏼 |
d567704
to
437eeee
Compare
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.
Thanks for doing this.
I'm also sorry it took so long for me to check out. I've been buried in work for the last few weeks.
I have question: why is the call history log a singleton? I don't think it should be.
Hi @mcollina ! I saw that, don't worry about, i looked at your work and maintaining all of this open source projects + a job is not an easy part ;) To answer at your question :
NB : the main purpose of the static class method is to avoid to register and associate an history instance to a MockAgent or a MockScope. In my own opinion, this is the most simple way to do it and the safer way to register multiple instance when constructing multiple MockAgent / MockScope withou having to forget to delete them. |
Can you please remove it, and have it passed directly to |
Ok i will rollback to my previous implementation, but delete the ability to bind a mockCallHistory instance to a mockDispatch because without this static class method, i cannot get the mockCallHistory associated with a mockDispatch with
WDYT @mcollina ? ps : i can do it this night |
that should work |
437eeee
to
78892ff
Compare
78892ff
to
0f6f62e
Compare
This relates to...
#4025
Rationale
Actually we are not able with MockAgent to assert request configuration.
Given this in mind, the only way we could do it is by wrapping our app http call in function, and then spy or mock that function with our favorite test framework. We can make assertions on parameters we passed through that function but, even with this possibility, we are not certain that undici did not make computation on inputs.
This PR is addressing this problematic : ensuring http calls are made with the expected low level configuration, as far as we can.
Changes
getCallHistory
class method to MockAgent instanceclearCallHistory
class method to MockAgent instancedisableCallHistory
class method to MockAgent instanceenableCallHistory
class method to MockAgent instanceenableCallHistory
MockAgent instantiation optionsMockAgent.close
is calledFeatures
Given this application :
After :
Before :
Status