lundi 29 juillet 2019

How to expose/access a data store state within a cypress test in an Angular app?

I'm trying to create some Cypress tests for an Angular 7 application which uses ngrx-store. I was hoping to pre-load some data into the store in order to then test the UI. Unfortunately I am not sure how to directly load the required data into the store, without using a dispatch.

I have managed to expose the store, as described in this example (How to expose/access a data store like Redux within a cypress test?) however I would like to manipulate the state directly without dispatching an action. My guess is I somehow need to set a test-specific initial state for the store/state

Here's what I did so far:

    // in app.component
    if (window.Cypress) {
                // @ts-ignore
                window.__appStore__ = store$;
            }

    // in the test
    cy.window().then(w => {
            console.log(w.__appStore__);
    }

The above works fine. I get the store, but can only manipulate it through its API. What I really want is the state of the the store to manipulate it directly.

Aucun commentaire:

Enregistrer un commentaire