https://cypress.io logo
Hi folks, I'm having a problem with the use of a ...
# e2e-testing
n
Hi folks, I'm having a problem with the use of a "setTimetout" inside my app component. The timeout is called immediately during tests but works as expected when running the app normally. I don't discard this as a bug in my code but couldn't figure it out. Can anybody help me? The Vue component watches for changes in the session expiration date and schedule setTimeout to end the user session when due.
Copy code
// ...
  watch: {
    sessionExpiration: {
      handler: 'startSessionTimer',
      immediate: true
    },
    // ...    
  },
  methods: {
    // ...
    startSessionTimer (expiration) {
      this.clearTimer();
      if (!expiration) return;

      const timeout = expiration.getTime() - Date.now();
      console.log({ expiration, now: new Date(), timeout });

      this.timeoutId = setTimeout(() => {
        console.log({ timeoutExecuted: new Date() });
        // this.alertAndSignOut();
      }, timeout);
    },
// ...
Things work OK when I run the app, but during e2e tests, the setTimeout executes immediately, even with very lengthy expiration dates.