Closed twgraham closed 4 years ago
Hi @twgraham . What you need to do in your case is first open the connection in your test using cy.stream(config) and decide what event will complete the stream such that it closes at some point. (see example in Readme) Then you start your automated clicks using the normal cypress mechanisms and check the results. But again, it's important that there is an event (time, amount of clicks etc) that will close the stream. Have a look at https://www.learnrxjs.io/operators/filtering/takeuntil.html to see different ways to trigger the socket closing. Let me know if it worked or if you have any other questions.
Thanks @dsebastian .
What I ended up doing was opening a stream with some filters then assigning it to a promise. I then would perform some actions, and have cypress wrap (and wait) for the promise after.
e.g.
cy.stream<Message>().then((ws) => {
const socketMessageAsync: Promise<Message> = sub.pipe(
doSomething(),
andThen(),
somethingElse(),
takeUntil(timer(4000))
).toPromise()
cy.get('button').contains(/Lorem Ipsum/i)
.click()
.findByRole('alert').should('contain', 'You clicked lorem ipsum')
.logout()
cy.wrap<Promise<Message>, Message>(socketMessageAsync)
.then((message) => {
doSomethingWithResult(message)
})
})
Great work on this library!
Could you advise how the following use case might be approached?
My websocket sends notifications in realtime - it doesn't send notifications that might exist before it was opened.
A flow might look like:
I've tried to open the socket and alias the promise created by
myStream.toPromise()
(this doesn't work too well with cypress).