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

RequetErrorEvent during Jest testing. #11965

Closed
McKayMower opened this issue Apr 30, 2024 · 1 comment
Closed

RequetErrorEvent during Jest testing. #11965

McKayMower opened this issue Apr 30, 2024 · 1 comment

Comments

@McKayMower
Copy link

What happened?

I am writing tests in Jest.

I have a React component for the Cesium viewer:

import React from "react"
import { CesiumComponentRef, Viewer } from "resium"

import { terrain } from "@/lib/cesiumConfig"
import getWebGLStub from "@/lib/helpers/getWebGLStub"
import { cn } from "@/lib/utils"
import { Viewer as CViewer } from "cesium"

(window as any).CESIUM_BASE_URL = window.location.href ?? "/"

interface Props {
  children?: React.ReactNode
  className?: string
  testing?: boolean
}

const ForwardRefCesium = React.forwardRef<CesiumComponentRef<CViewer>, Props>(({ children, className, testing = false }, ref) => {
  return <Viewer ref={ref}
    contextOptions={testing ? {
      getWebGLStub: getWebGLStub
    } : undefined}
    className={cn('relative flex z-[0] overflow-clip flex-1', className)}
    full
    timeline={false}
    animation={false}
    baseLayer={testing ? false : undefined}
    baseLayerPicker={false}
    sceneModePicker={false}
    navigationHelpButton={false}
    fullscreenButton={false}
    geocoder={false}
    selectionIndicator={false}
    terrain={testing ? undefined : terrain}
    homeButton={false}
    infoBox={false}
    skyBox={false}
    scene3DOnly={true}
    automaticallyTrackDataSourceClocks={false}
    skyAtmosphere={false}>
    {children}
  </Viewer>
})

export default ForwardRefCesium

ForwardRefCesium.displayName = "Cesium"

Now, in my Jest tests, I am failing tests due to request errors. See the image below.

image

Something to note: I am testing in a headless environment so I use the getWebGLStub helper function found in the cesium repository.

Since I am testing in a headless environment window.location (which is used in the requests) will be undefined. When I go to render my component, it appears the requests for imagery layers are sent off. How can I disable these requests? Since these requests throw the error seen below, the tests automatically fail.

image

Reproduction steps

...

Sandcastle example

No response

Environment

Browser: N/A
CesiumJS Version: 1.115
Operating System: Ubuntu 22.04.3 LTS

@ggetz
Copy link
Contributor

ggetz commented May 3, 2024

Hi @McKayMower, you can turn off imagery by providing the option baseLayer: false to the viewer.

In many CesiumJS tests, we also stub out web requests to help with reliability. The exact mechanic of how to do that depends on your particular app though.

CesiumJS is a big project, so we use GitHub for feature requests and bug tracking exclusively. In the future, please take any questions to the Cesium Forum where there are members of the community and developers from the team who can help. Thanks!

@ggetz ggetz closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants