import { timer } from "rxjs" ; import { takeUntil , reduce } from "rxjs/operators" ; import { WebSocketSubjectConfig } from "rxjs/webSocket" ; type MessageType = "CONNECTED" | "LOGIN" | "RECORD" | "END" ; interface IMessage { type : MessageType ; data : any ; } const config = { url : "ws://localhost:8080/" } ; context ( "Websocket cy.stream() Command" , ( ) => { it ( "Simple subscribe with close callback to complete" , done => { cy . stream < IMessage > ( config ) . then ( subject => { subject . pipe ( takeUntil ( timer ( 1000 ) ) , reduce ( ( acc , val ) => acc . concat ( [ val ] ) , [ ] ) ) . subscribe ( { next : ( results ) => { const length = ( results && results . length ) || 0 ; const result = results && results [ length - 1 ] ; expect ( length ) . to . eq ( 1 ) ; expect ( result ) . to . not . be . undefined ; expect ( result ) . to . have . property ( "type" , "CONNECTED" ) ; expect ( result ) . to . not . have . property ( "data" ) ; } , error : ( err ) => { } , complete : done } ) ; } ) ; } ) ; } ) ;