mardi 28 août 2018

How to expose/access a data store like Redux within a cypress test?

The Cypress docs say you can

Expose data stores (like in Redux) so you can programmatically alter the state of your application directly from your test code.

I also watched a course on testing by Mr. Kent C. Dodds where he mentions a redux store could be initialized with existing data in Cypress (before or within tests, not sure)

I went through pretty much all the docs and googled and I just can't find any references or examples of actually doing this other than it being mentioned as one of the key differences on the introductory page.

How does one achieve something like that, if possible?

The case I am interested in is for E2E tests:

  • First I would test my auth/login functionality as a standard E2E test
  • Then for testing other parts of the application I would add a Cypress Command that would directly make the auth call and set up the store from the response whenever I needed to log in (same for log out), instead of manually typing in the credentials & clicking log in (which might be what I end up doing anyway)

This might not be the best use case (or a good one even) but I'm sure there are other cases where at least initializing your redux state with some data would come in very handy.

Thanks!

1 commentaire:

  1. You can create a 'login' command and run this function before the other tests.

    RépondreSupprimer