-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(mock): emit 'request', 'overwrite', 'fail', 'match', 'continue' events #10137
feat(mock): emit 'request', 'overwrite', 'fail', 'match', 'continue' events #10137
Conversation
45c4998
to
25fd483
Compare
25fd483
to
695606b
Compare
695606b
to
8b43c1c
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.
The change looks good to me. Can you provide the motivation of this change and maybe add it to the docs section for people that skim through them can immediately for what this is useful?
Sure. Added some examples in In addition, you could also modify props of object, passed to event handler, but for now i could not imagine use-cases for that. Also, here is the order of emitting events:
|
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.
Great examples! Some last questions.
a23d469
to
1476a8f
Compare
website/docs/api/Mock.md
Outdated
Throwing an error on 404 network fail: | ||
|
||
```js | ||
const loadPage = (browser, url, {selector, predicate}) => new Promsie(async (resolve, reject) => { |
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.
How about we wrap this into a custom command, e.g.
await browser.addCustomCommand('loadPageWithout404', (url, { selector, predicate }) => { ... })
browser.loadPageWithout404('some/url', { selector: 'main' })
Seems to be more WebdriverIO native.
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.
Done
1476a8f
to
65b8e26
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.
Awesome, thanks a lot 👍
Proposed changes
Make a mock EventEmitter, emitting
request
,overwrite
,fail
,continue
eventsrequest
is being emitted on requestoverwrite
is being emitted if response is being overwrited byrespond
/respondOnce
fail
is being emitted if request is aborted byabort
/abortOnce
match
is being emitted when request is added tomatches
array (beforecontinue
oroverwrite
) (it hasmockedResponse
property ifoverwrite
is provided)continue
is being emitted if mock is a spy of if response was already sent (like in case with two mocks. If two mock patterns match current request, and both of them has some overwrites. Then first mock will triggeroverwrite
event, and the second one will triggercontinue
)Types of changes
Checklist
Further comments
Will be provided in self-review by lines
Reviewers: @webdriverio/project-committers