important-park-97069
05/30/2022, 3:08 AMimportant-park-97069
05/30/2022, 3:08 AMdazzling-thailand-64429
05/30/2022, 3:58 AMdazzling-thailand-64429
05/30/2022, 3:58 AMdazzling-thailand-64429
05/30/2022, 3:59 AMdazzling-thailand-64429
05/30/2022, 4:00 AMdazzling-thailand-64429
05/30/2022, 4:01 AMbig-electrician-80156
05/30/2022, 1:31 PMpowerful-gigabyte-69168
05/30/2022, 2:29 PM// main.js
import { useCounterStore } from '@/stores/counter';
if (window.Cypress) {
const counterStore = useCounterStore();
window.counterStore = counterStore;
}
now you can access the exposed store during testing like
// Get the pinia store directly off the window object
cy
.window()
.its('counterStore')
.then((counterStore) => {
expect(counterStore.counter).to.eq(0);
});
Big thanks to the folks here for helping me think through the problem. Here's my recipe repo: https://github.com/itsalaidbacklife/cypress-pinia-compositiongray-kilobyte-89541
05/30/2022, 2:35 PMgray-kilobyte-89541
05/30/2022, 2:36 PMcy.then
since it breaks the retry-ability, just write
js
// Get the pinia store directly off the window object
cy
.window()
.its('counterStore.counter').should('equal', 0)
powerful-gigabyte-69168
05/30/2022, 2:38 PM.then()
doesn't have retry built in because it anticipates potential side effects, whereas should is purely for assertions and will automatically retry?gray-kilobyte-89541
05/30/2022, 2:40 PMpowerful-gigabyte-69168
05/30/2022, 2:42 PM.then()
if I wanted to use cypress to trigger a store action with side effects (like firing off an api call through application logic) but .should()
to read state for assertionsimportant-park-97069
05/30/2022, 3:15 PMcy.intercept('https://api.somesite.com/test-url', ...handler);
cy.intercept('test-url/**', ...handler);
In this case, the first handler would be the one that is used when, say, a GET reaches out to https://api.somesite.com/test-url/12345
?important-park-97069
05/30/2022, 3:17 PMimportant-park-97069
05/30/2022, 3:17 PMimportant-park-97069
05/30/2022, 3:17 PMadventurous-dinner-77554
05/30/2022, 5:09 PMmysterious-sandwich-43667
05/30/2022, 5:33 PMcool-engineer-68430
05/31/2022, 8:49 AMred-butcher-91574
05/31/2022, 11:18 AMproud-printer-45627
05/31/2022, 1:15 PMelegant-dress-62146
05/31/2022, 2:38 PMfew-easter-79970
05/31/2022, 2:42 PMnarrow-gigabyte-35813
05/31/2022, 4:15 PMpowerful-gigabyte-69168
05/31/2022, 7:22 PMpowerful-gigabyte-69168
05/31/2022, 7:25 PM.equal()
? It's really interesting that if you provide a second (string) argument that has a ',' in it, it seems to log the beginning of the string upon success and the entire string upon failure, which makes for some pretty nice reporting:proud-printer-45627
06/01/2022, 7:18 AMgreen-book-63455
06/01/2022, 8:19 AM