Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of null (reading 'top') #145

Open
eltongonc opened this issue Jun 28, 2023 · 0 comments
Open

Cannot read properties of null (reading 'top') #145

eltongonc opened this issue Jun 28, 2023 · 0 comments

Comments

@eltongonc
Copy link

While running some tests I run into the following error:

TypeError: The following error originated from your application code, not from Cypress.

  > [My-app]Cannot read properties of null (reading 'top')

When Cypress detects uncaught errors originating from your application it will automatically fail the current test.

This behavior is configurable, and you can choose to turn this off by listening to the `uncaught:exception` event.

Looking deeper into the error I notice the issue comes from the
this.selectedElementRect.top in the else statement in the code below:

//  ngx-guided-tour/projects/ngx-guided-tour/src/lib/guided-tour.component.ts

scrollToAndSetElement() {
    this.updateStepLocation();
    // Allow things to render to scroll to the correct location
    setTimeout(() => {
      if (!this.isOrbShowing && !this.isTourOnScreen()) {
        if (this.selectedElementRect && this.isBottom()) {
          // Scroll so the element is on the top of the screen.
          const topPos = this.windowRef.nativeWindow.scrollY + this.selectedElementRect.top - this.topOfPageAdjustment - (this.currentTourStep.scrollAdjustment ? this.currentTourStep.scrollAdjustment : 0) + this.getStepScreenAdjustment();
          try {
            this.windowRef.nativeWindow.scrollTo({
              left: null,
              top: topPos,
              behavior: 'smooth'
            });
          } catch (err) {
            if (err instanceof TypeError) {
              this.windowRef.nativeWindow.scroll(0, topPos);
            } else {
              throw err;
            }
          }
        } else {
          // Scroll so the element is on the bottom of the screen.
          const topPos = this.windowRef.nativeWindow.scrollY + this.selectedElementRect.top + this.selectedElementRect.height - this.windowRef.nativeWindow.innerHeight + (this.currentTourStep.scrollAdjustment ? this.currentTourStep.scrollAdjustment : 0) - this.getStepScreenAdjustment();
          try {
            this.windowRef.nativeWindow.scrollTo({
              left: null,
              top: topPos,
              behavior: 'smooth'
            });
          } catch (err) {
            if (err instanceof TypeError) {
              this.windowRef.nativeWindow.scroll(0, topPos);
            } else {
              throw err;
            }
          }
        }
      }
    });
  }
eltongonc added a commit to eltongonc/ngx-guided-tour that referenced this issue Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant