https://cypress.io logo
Hi everyone, I'm trying to use my angular programa...
# i-need-help
b
Hi, I'm using firestore as a database for my app, I have it in a service and I want to manipulate it in my tests. I expose it via the window object, basically in my app, if it's built as e2e, it will do window.e2eFirestore = this This works fine, but my problem is how to await for async functions to complete. So I'm currently doing something like this:
Copy code
const setup = () => {
    cy.window()
      .its('e2eFirestore')
      .then(
        (firestore: FirestoreService) =>
          new Cypress.Promise(async (resolve) => {
            await firestore.update(id, {
              test: 'test'
            });
            resolve();
          })
      );
}

it('test', () => {
  setup(); // doesn't wait for test data to be written in the db
  cy.visit('/');
  // it should display test data, but it doesn't, that gets loaded after
})
It seems cypress is not waiting for the Cypress Promise to complete. What is the recommended approach for handling async api functionality? I don't want to visit the route until the data has been stored in the db. Thank you in advance!
2 Views