# Can not run jest test after migrate strato to 0.100

**URL:** <https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800>\
**Category:** Developer Q&A Forum\
**Tags:** strato, custom-app\
**Created:** [September 27, 2023, 1:06pm UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800 "2023-09-27T13:06:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![beigert](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/beigert/32/7422_2.png) [@beigert](https://community.dynatrace.com/u/beigert)\
**Post date:** [September 27, 2023, 1:06pm UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800/1 "2023-09-27T13:06:47Z")

</div>

After migration `@dynatrace/strato-components-preview` from 0.99 to 0.104 every unit test is failing with the same error:

```

FAIL src/app/components/BuildsOverTimeContainer.spec.tsx  
● Test suite failed to run

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 [ECMAScript Modules · Jest](https://jestjs.io/docs/ecmascript-modules) for how to enable it.  
• If you are trying to use TypeScript, see [Getting Started · Jest](https://jestjs.io/docs/getting-started#using-typescript)  
• 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:

> **[Configuring Jest · Jest](https://jestjs.io/docs/configuration)**
>
> The Jest philosophy is to work great by default, but sometimes you just need more configuration power.

For information about custom transformations, see:

> **[Code Transformation · Jest](https://jestjs.io/docs/code-transformation)**
>
> Jest runs the code in your project as JavaScript, but if you use some syntax not supported by Node out of the box (such as JSX, TypeScript, Vue templates) then you'll need to transform that code into plain JavaScript, similar to what you would do...

Details:

/Users/user/code/dynatrace/node\_modules/@dynatrace/strato-design-tokens/colors/index.esm.js:15  
…  
SyntaxError: Unexpected token ‘export’

at Runtime.createScriptFromCode (node\_modules/jest-runtime/build/index.js:1505:14)  
at Object.\<anonymous\> (node\_modules/@dynatrace/strato-components-preview/core/index.cjs.js:131:30)```

jest.config.ts:  
```

import type { Config } from “@jest/types”;

import { stratoPreset } from “@dynatrace/strato-components-preview/testing/jest”;

const config: Config.InitialOptions = {  
&nbsp; preset: “ts-jest”,  
&nbsp; testEnvironment: “jsdom”,  
roots: [“\<rootDir\>/src”],  
&nbsp; setupFiles: [“@dynatrace/strato-components-preview/testing”],  
&nbsp; transform: {  
&nbsp; &nbsp; “.(css|scss|sass|less)$”: “\<rootDir\>/style-mock.ts”,  
&nbsp; },  
&nbsp; setupFilesAfterEnv: [`\<rootDir\>/src/jest-setup.ts`],  
&nbsp; …stratoPreset,  
&nbsp; moduleNameMapper: {  
&nbsp; &nbsp; …stratoPreset.moduleNameMapper,  
&nbsp; &nbsp; “^libs/(.\*)”: “\<rootDir\>/src/libs/$1”,  
&nbsp; &nbsp; “^components/(.\*)”: “\<rootDir\>/src/app/components/$1”,  
&nbsp; &nbsp; “^hooks/(.\*)”: “\<rootDir\>/src/app/hooks/$1”,  
&nbsp; &nbsp; “^contexts/(.\*)”: “\<rootDir\>/src/app/contexts/$1”,  
&nbsp; },  
};

export default config;  
```

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [September 27, 2023, 5:04pm UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800/2 "2023-09-27T17:04:52Z")

</div>

Hi [@beigert](https://community.dynatrace.com/user/59122)&nbsp;,

Can you add this in your module name resolution config (jest.config.ts):

```markup
moduleNameMapper: {
    "^@dynatrace/strato-design-tokens/(.*)$": "<rootDir>/node_modules/@dynatrace/strato-design-tokens/$1",
    "^@dynatrace/strato-design-tokens$": "<rootDir>/node_modules/@dynatrace/strato-design-tokens",
  },

```

and check if this fixes your problem?

Best,  
Sini

---

<div class="post-metadata">

**Author:** ![beigert](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/beigert/32/7422_2.png) [@beigert](https://community.dynatrace.com/u/beigert)\
**Post date:** [September 28, 2023, 9:46am UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800/3 "2023-09-28T09:46:43Z")

</div>

it helps a little bit: tests that don’t import anything from `strato-components-preview` works. However rest of them fail with the same error:

```

FAIL src/app/components/BuildsOverTimeContainer.spec.tsx  
● Test suite failed to run

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 [ECMAScript Modules · Jest](https://jestjs.io/docs/ecmascript-modules) for how to enable it.  
• If you are trying to use TypeScript, see [Getting Started · Jest](https://jestjs.io/docs/getting-started#using-typescript)  
• 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:

> **[Configuring Jest · Jest](https://jestjs.io/docs/configuration)**
>
> The Jest philosophy is to work great by default, but sometimes you just need more configuration power.

For information about custom transformations, see:

> **[Code Transformation · Jest](https://jestjs.io/docs/code-transformation)**
>
> Jest runs the code in your project as JavaScript, but if you use some syntax not supported by Node out of the box (such as JSX, TypeScript, Vue templates) then you'll need to transform that code into plain JavaScript, similar to what you would do...

Details:

/Users/przemyslawbeigert/code/dynatrace/pipeline-observability-application/node\_modules/@dynatrace/strato-components-preview/index.esm.js:2  
export \* from “@dynatrace/strato-components-preview/buttons”;  
^^^^^^

SyntaxError: Unexpected token ‘export’

\> 1 | import { Flex, Skeleton } from “@dynatrace/strato-components-preview”;  
| ^  
2 | import { TimeseriesChart } from “@dynatrace/strato-components-preview/charts”;  
3 | import Colors from “@dynatrace/strato-design-tokens/colors”;  
4 | import { InformationIcon } from “@dynatrace/strato-icons”;

at Runtime.createScriptFromCode (node\_modules/jest-runtime/build/index.js:1505:14)  
at Object.\<anonymous\> (src/app/components/BuildsOverTimeContainer.tsx:1:1)  
at Object.\<anonymous\> (src/app/components/BuildsOverTimeContainer.spec.tsx:10:1)  
```

* * *

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [September 28, 2023, 12:52pm UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800/4 "2023-09-28T12:52:28Z")

</div>

[@beigert](https://community.dynatrace.com/user/59122)&nbsp;unfortunately I can’t help you further. Please create a support ticket in&nbsp;&nbsp;[https://one.dynatrace.com/hc/en-us/requests](https://one.dynatrace.com/hc/en-us/requests)&nbsp;with a reference to this thread and the error messages. Our developers need to have a detailed look at it.

Thx,  
Sini

---

<div class="post-metadata">

**Author:** ![beigert](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/beigert/32/7422_2.png) [@beigert](https://community.dynatrace.com/u/beigert)\
**Post date:** [October 4, 2023, 8:44am UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800/5 "2023-10-04T08:44:57Z")

</div>

It works, however after clear the cache by `rm -rf node_modules/.cache`. However pls update docs:&nbsp;[Create unit tests with Jest | Dynatrace Developer](https://developer.dynatrace.com/develop/testing/unit-tests/)

---

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [October 6, 2023, 7:04am UTC](https://community.dynatrace.com/t/can-not-run-jest-test-after-migrate-strato-to-0-100/41800/6 "2023-10-06T07:04:31Z")

</div>

Just synced with the team about this.

this workaround won’t be needed anymore with design system version 0.106.2 and design tokens version 0.19.0
