Accessing @ionic/storage from Cypress.io

Is it possible to access the @ionic/storage driver from the global window object? I’m trying out cypress io for e2e testing, and it would be a convenient means to automate login to directly read write to indexeddb without having to re-implement the basics of connecting to the right database, dealing with transactions, and so forth.

I believe I’ve come up with a solution to this on my own. In my Cypress.io spec, I can just do the following:

// globals in the file
const Storage = require('@ionic/storage').Storage;
const storage = new Storage();

… and at that point it seems like storage is available in my tests just as though it had been injected into an Angular class.

This would create a new storage object, but without any reference to Angular, which could be fine.
But check out how you would access regular providers in Angular with cypress.

1 Like