You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
@LayZeeDK opened a fantastic PR #227 to add an example of integrating jest-preview with Angular. However, jest-preview cannot process styles defined in styleUrls and styles. The situation is very similar to Vue Scoped CSS (see #42 (comment))
In other words, styling like this does not work with jest-preview (Don't forget to check Workaround below)
jest-preview should support all the styling specified by styleUrls and styles via code transformation.
Describe how should jest-preview implements this feature
Context
The current transformer Angular is using is jest-preset-angular (Not sure if there is any other angular transformer in the wild?). jest-preset-angular by default drop all the CSS (it used to make sense since before jest-preview, there is nothing to do with CSS in testing FE apps in Node.js, see @LayZeeDK's explanation #227 (comment))
Possible solutions
So, there are some options I had in mind:
Write our own jest code transformation for Angular, then instruct users to use it. We can fork or learn how jest-preset-angular process Angular code.
Write our own jest code transformation, but like a wrapper, execute jest-preset-angular first, then process CSS later
(prefer) Contact jest-preset-angular author and discuss with them to support processing CSS in jest environment. You can send a PR to upstream to add this feature.
Do not process CSS by default.
We can configure jest-preset-angular to process CSS similar to @swc/jest. Reference.
This will not be a quick fix. But it will be an interesting problem to solve. @nvh95 might ask @LayZeeDK for support since he is already an expert in Angular community 🤩.
Are there any other solutions? Please comment below, thanks.
Until jest-preview can have first-class support for Angular. You can still workaround with CSS by importing it directly to test files. jest-preview can process CSS by this way. For example:
// app.component.spec.ts
+import '../styles/css/app.css';+import '../styles/scss/style.scss';+import './app.component.css';
describe('App', () => {
it('should work as expected', async () => {
// your tests
});
});
Before this workaround:
After this workaround:
I haven't known how to workaround for style defined directly with styles.
Is your feature request related to a problem? Please describe.
@LayZeeDK opened a fantastic PR #227 to add an example of integrating
jest-preview
with Angular. However,jest-preview
cannot process styles defined instyleUrls
andstyles
. The situation is very similar to Vue Scoped CSS (see #42 (comment))In other words, styling like this does not work with
jest-preview
(Don't forget to check Workaround below)Describe the solution you'd like
jest-preview
should support all the styling specified bystyleUrls
andstyles
via code transformation.Describe how should jest-preview implements this feature
Context
The current transformer Angular is using is jest-preset-angular (Not sure if there is any other angular transformer in the wild?).
jest-preset-angular
by default drop all the CSS (it used to make sense since beforejest-preview
, there is nothing to do with CSS in testing FE apps in Node.js, see @LayZeeDK's explanation #227 (comment))Possible solutions
So, there are some options I had in mind:
jest-preset-angular
process Angular code.jest-preset-angular
first, then process CSS laterjest-preset-angular
author and discuss with them to support processing CSS injest
environment. You can send a PR to upstream to add this feature.jest-preset-angular
to process CSS similar to@swc/jest
. Reference.This will not be a quick fix. But it will be an interesting problem to solve. @nvh95 might ask @LayZeeDK for support since he is already an expert in Angular community 🤩.
Are there any other solutions? Please comment below, thanks.
Describe alternatives you've considered/ Workaround
Until
jest-preview
can have first-class support for Angular. You can still workaround with CSS byimport
ing it directly to test files.jest-preview
can process CSS by this way. For example:Before this workaround:
After this workaround:
I haven't known how to workaround for style defined directly with
styles
.Additional context
Please see PR #227 and angular example at https://github.com/nvh95/jest-preview/tree/main/examples/angular
The text was updated successfully, but these errors were encountered: