seb-oss / green

Green is an open-source design system built by SEB.
https://storybook.seb.io/
Apache License 2.0
37 stars 55 forks source link

Modal: Unit tests failing #1601

Closed karolis-leonas closed 1 month ago

karolis-leonas commented 2 months ago

Angular application unit tests (Jest) with NggModal import seem to be failing to run now

Bug already reported?

For which framework/library you are reporting the bug

Angular

Component name

modal

Description

Hello, not sure if unit testing issues with Green imports should be communicated as an issue, but I'm trying my luck here now since I feel stuck at the moment :) So, after trying out updating Green versions to newer ones, we noticed that some of our unit tests which reference NggModalModule import seem to be failing to run now, even though they did work before without code changes.

Testing framework throws an error:

"Test suite failed to run TypeError: tokesStyleSheets.replaceSync is not a function"

This issue happens with:

Do you know if there are any recent or important changes for NggModalModule which could have caused this kind of error to be thrown, or if you know by any change on how can we mitigate it?

If you have more questions - please contact me.

Huge thanks in advance!

Steps To Reproduce

No response

Current Behaviour

Currently our failing Jest unit tests throw this kind of response: image

Expected Behaviour

Test suite should start running properly as it did before.

splashdust commented 1 month ago

You need to mock some browser APIs ro run Green Core in Jest. Here's a guide: https://storybook.seb.io/latest/angular/?path=/docs/testing--docs

Also, when you import the component, you should import it from the sub path:

import { NggModalModule } from '@sebgroup/green-angular/src/lib/modal'

Otherwise you end up importing the entire library, which includes web components you may not be using. Since those are automatically registered with the browser (ie, side-effects), the compiler cannot tree-shake them.

karolis-leonas commented 1 month ago

Thanks a lot, your suggestion and linking to the support docs solved our issue! Closing this ticket now.