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

Using getCurrentState #364

Open
hausdora opened this issue Sep 23, 2022 · 0 comments
Open

Using getCurrentState #364

hausdora opened this issue Sep 23, 2022 · 0 comments

Comments

@hausdora
Copy link

hausdora commented Sep 23, 2022

When I run .getCurrentState I get back an object with two properties. But I'm having trouble doing anything with them.

const state = cy.getReact("Comp").getCurrentState();
cy.log(state); 
//logs: {hidden: false, context: Object{6}} 

const state = cy.getReact("Comp").getCurrentState().context;
cy.log(state); 
//logs nothing

Nothing I'm trying works, how do I make assertions against the getCurrentState return?

        cy.getReact("Comp").getCurrentState()
        .should(($state) => {
          expect($state.context.active.should("have.length", 3))
        });

Attempt 2

cy.getReact("Comp").getCurrentState("context.active").should("have.length", 3)

Attempt 3

        const state = cy
          .getReact("Graphin")
          .getCurrentState()
          .then((data) => cy.log(JSON.stringify(data)));
        cy.log(state);

//Throws TypeError:
Converting circular structure to JSON
    --> starting at object with constructor 'HTMLDivElement'
    |     property '__reactInternalInstance$977odfgpjmb' -> object with constructor 'FiberNode'
    --- property 'stateNode' closes the circle

It doesn't seem to work like getProps, but I can't find any documentation on how I would make assertions against the return.

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