Skip to content
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

Cannot read properties of undefined #32

Open
LeandroPereiraMB opened this issue Aug 31, 2022 · 0 comments
Open

Cannot read properties of undefined #32

LeandroPereiraMB opened this issue Aug 31, 2022 · 0 comments

Comments

@LeandroPereiraMB
Copy link

I'm trying to get messages from a WebSocket to make assertions using Cypress. I used the example from the website [link] (https://github.com/lensesio/cypress-websocket-testing/blob/master/README.md) to do the automation.

Basically, I made a post to a Rest service and then I listen to WebSocket to see if any new messages are displayed.

The first statement passes, but the second does not. Cypress displays a message saying: "Cannot read properties of undefined (reading 'payload').

The console.log command does not print anything to the console. I think the return message from the WebSocket is not being stored in the "result" variable.

It looks like cypress is not reading all messages sent by WebSocket. Could anyone tell me what's wrong with my code?

`///

import { addStreamCommands } from '@lensesio/cypress-websocket-testing';

addStreamCommands();

describe('Should create investment ', () => {

it('Should create investment type commitment', () => {

    const ws = 'wss://xxxx.xxxx.xxx.xx/api/v1/ws'

    cy.request({
        method: 'POST',
        headers: {
            Authorization: `Bearer ${'xxxxxxxxxxxxxxxxxx'}`},
            
        url:'https://xxxx.xxxx.xxx.xx/api/v1/investment',
        body:{
            "projectId": 40,
            "quoteAssetQuantity": "5100",
            "investmentType": "Commitment"
        }
    })
    cy.streamRequest(ws).then(result => {
        console.log(result)
        expect(result).to.not.be.undefined;
        expect(result[0].payload.InvestmentId).to.eq('906')
        
    })
})

})`

image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant