Jest testing with Resium

There is no Resium category so I’m adding this here, but please let me know if I should post this elsewhere…

Anyone managed to implement jest unit tests for a Resium app?

Here’s what I tried:

import React, { FC } from "react";
import { Viewer } from "resium";
import getWebGLStub from "../getWebGLStub";

interface TestViewerWrapperProps {
	componentToTest: React.ReactNode;

const TestViewerWrapper: FC<TestViewerWrapperProps> = (props) => {
	return (
				contextOptions={{ getWebGLStub: getWebGLStub }}

export default TestViewerWrapper;

import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import TestViewerWrapper from "../../testing/TestViewerWrapper/TestViewerWrapper";
import { useCesium } from "resium";

interface WrapperProps {}
function Wrapper(props: WrapperProps) {
	const { viewer } = useCesium();
	return (
			{viewer ? (
			) : null}

describe("<DemoButton />", () => {
	test("it should mount", () => {
		render(<TestViewerWrapper componentToTest={<Wrapper></Wrapper>} />);
		const demoButton = screen.getByTestId("DemoButton");

I added getWebGLStub.js based on Testing Cesium in Jest - #8 by shane_benlolo, I simply copied the file from the github repo mentioned in the last May 10 post on that link.

This is the error I get:

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see for how to enable it.
 • If you are trying to use TypeScript, see
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
For information about custom transformations, see:


export { default as AutomaticUniforms } from './Source/Renderer/AutomaticUniforms.js';

SyntaxError: Unexpected token 'export'

> 1 | import { clone, defaultValue, defined, DeveloperError, WebGLConstants } from "@cesium/engine";
    | ^
  2 |
  3 | function getWebGLStub(canvas, options) {
  4 |       const stub = clone(WebGLConstants);

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
  at Object.<anonymous> (src/testing/getWebGLStub.js:1:1)
  at Object.<anonymous> (src/testing/TestViewerWrapper/TestViewerWrapper.tsx:2:1)
  at Object.<anonymous> (src/components/DemoButton/DemoButton.test.tsx:8:1)
  at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
  at runJest (node_modules/@jest/core/build/runJest.js:404:19)

So clearly there is something wrong with the way I’m trying to use getWebGLStub.js. It is indeed a weird way to do it, but does anyone have suggestions?