-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
A "Testing with Material Components" guide to demonstrate including core theme in test suite #4056
Comments
@willshowell i have the same issue, i am with angular 4 and the newset beta 3 of angular material with a custom theme |
I am using the custom theme with
Importing that in file
As I am using
And I am on From
|
I have this configuration:
|
you are missing
|
@kuncevic oops :), i just forgot to wrote it here in comment but it exist in code: BTW i am not use the '_theming' but the 'theming' Thanks 4 your help :) |
actually I just run |
From what I understand, karma does not inject any css into your tests by default, but including a material component without a theme will trigger the warning. In my original comment I showed how to inject one of the prebuilt themes into the test suite. What I don't know is if this is the ideal solution. I figure there should either be something in the docs about it, or the warning should stay silent during unit tests that import material modules. Maybe @devversion or @crisbeto can weigh in? |
Another issue with receiving warnings- I've also noticed that the ".css.map" files seem to be missing in beta.3, so I keep getting thrown the following in Chrome:
Is this the case, or am I just unable to find it? The ".css.map" files do not exist in the "/prebuilt-themes" directory. |
I think the real solution here is that there should be guide specifically for testing w/ the Material components. |
Now in docs we have:
I use:
When I import css-file in @import '~@angular/material/prebuilt-themes/indigo-pink.css'; and run project via
When I do @import '~@angular/material/theming'
/* or @import '~@angular/material/_theming'*/ I have error "file not found". When I include the style in |
By running `ng eject`, 'angular-cli' exports `webpack-config.js`. This enables more tuning of the workflow and tool chain. Now, instead of running 'ng' commands, 'build' and such must be run directly or as npm/yarn scripts. With the dev tools installed locally, the commands must specify the tool path. This `ng eject` adds devDependencies. Specifying the versions as 'latest' in `package.json` enables `yarn upgrade` to grab the newest versions. The versions actually installed are tracked in `yarn.lock`. This way `package.json` does not restrict a dependency version unless doing so becomes necessary. Staying up-to-date becomes easier, and more predictable. https://yarnpkg.com/blog/2016/11/24/lockfiles-for-all/ Hovever, with 'postcss-url' v6, its _custom transform function_ option expects an options parameter instead of merely the url. The transform function supplied by `ng eject` was written to expect only the url. While fixing the transform function seems easy enough, maybe staying with the version the Angular team expects is safer -- at least for now. Downgrading and locking 'postcss-url' to v5.1 is easy with 'yarn'. It seems 'angular-cli' also was doing something more to inform 'karma' to load the Angular Material theme css. Specifying the css in `karma.conf.js` clears a karma warning: 'Could not find Angular Material core theme.' This issue may be specific to Angular Material v2.0.0-beta.3, or there may be a better solution coming. For more info, see angular/components#4056 Lastly, some webpack `devServer` options seem to have been left out by `ng eject`. Specifying these more closely match 'angular-cli' behavior. Further tuning webpack can happen later.
Sorry that I haven't been following the discussion here. If you're testing something that contains a Material component, you definitely need to include the theme, otherwise the positioning and a few other things won't be accurate. To do that, you need to add it to your Karma config. You can see how we're doing it for our own tests here. |
The problem with the way you do it it's Chinese for somebody who is just started to work with karma testing. If I put just the line you highlighted then it's not working, but the file is quite different to be able to figure out what's the problem. |
thanks @crisbeto , i changed my karma.conf.js
it workd. |
How we can add custom themes .scss files with angular-cli sass processing? |
custom themes being written in sass throw an error when including it in the files array of karma.conf.js
|
Any update on this? I'm not able to properly test any component using material. The error is showing up and no material animation is working in the components. |
…ta.4 (#64) * Core(): updated dependencies * Updated to latest flexlayout/material packages * Updated @covalent packages * Updated angular cli version * Updated d3/ngx charts * Fixed(themes): fixed import * Fixed import of material theming * Refactored(routing): added routing module * Added a routing module for the application to capsulate the configuration of the RouterModule * Feat(): added shared module * Added a shared module that contains all the elements that are shared across the different application modules * Refactored(app module): changed how the module is configurated * Moved import of routed components into app-routing.module * Moved styling modules into shared module * Others * Refactored(templates component): changes in html template * Added button directive to nav links * Refactored div elements into routed links in the covalent templates section * Core(): added missing script command * Added ng serve on start command * Fixed(editor component): added missing directive in html template * Added flex layout align directive * Fixed(shared module): added missing imports * Core(): updated dependencies * Updated to latest flexlayout/material packages * Updated @covalent packages * Updated angular cli version * Updated d3/ngx charts Fixed(themes): fixed import * Fixed import of material theming Refactored(routing): added routing module * Added a routing module for the application to capsulate the configuration of the RouterModule Feat(): added shared module * Added a shared module that contains all the elements that are shared across the different application modules Refactored(app module): changed how the module is configurated * Moved import of routed components into app-routing.module * Moved styling modules into shared module * Others Refactored(templates component): changes in html template * Added button directive to nav links * Refactored div elements into routed links in the covalent templates section Core(): added missing script command * Added ng serve on start command Fixed(editor component): added missing directive in html template * Added flex layout align directive Fixed(shared module): added missing imports * Refactored(shared module): fixed tslint warnings * Refactored(app routing module): minor changes * Fixed(karma config): added injection of material theme * Check angular/components#4056 * Fixed(): imports on component specs
* Core(): updated dependencies * Updated to latest flexlayout/material packages * Updated @covalent packages * Updated angular cli version * Updated d3/ngx charts * Fixed(themes): fixed import * Fixed import of material theming * Refactored(routing): added routing module * Added a routing module for the application to capsulate the configuration of the RouterModule * Feat(): added shared module * Added a shared module that contains all the elements that are shared across the different application modules * Refactored(app module): changed how the module is configurated * Moved import of routed components into app-routing.module * Moved styling modules into shared module * Others * Refactored(templates component): changes in html template * Added button directive to nav links * Refactored div elements into routed links in the covalent templates section * Core(): added missing script command * Added ng serve on start command * Fixed(editor component): added missing directive in html template * Added flex layout align directive * Fixed(shared module): added missing imports * Core(): updated dependencies * Updated to latest flexlayout/material packages * Updated @covalent packages * Updated angular cli version * Updated d3/ngx charts Fixed(themes): fixed import * Fixed import of material theming Refactored(routing): added routing module * Added a routing module for the application to capsulate the configuration of the RouterModule Feat(): added shared module * Added a shared module that contains all the elements that are shared across the different application modules Refactored(app module): changed how the module is configurated * Moved import of routed components into app-routing.module * Moved styling modules into shared module * Others Refactored(templates component): changes in html template * Added button directive to nav links * Refactored div elements into routed links in the covalent templates section Core(): added missing script command * Added ng serve on start command Fixed(editor component): added missing directive in html template * Added flex layout align directive Fixed(shared module): added missing imports * Refactored(shared module): fixed tslint warnings * Refactored(app routing module): minor changes * Fixed(karma config): added injection of material theme * Check angular/components#4056 * Fixed(): imports on component specs * refactored(template component): minor changes to html template * core(dependencies): corrected dependencies * Bumped @angular dependencies * Fixed downgraded @Material to beta5
I think this document would be a good place to suggest reading the tests from the source for figuring out how to test different components. It would cut down on a number of issues like "how do I access x in my tests?" and "x works fine in my app, but my tests fail" |
Well it gives me no error, but I still couldn't figure out how to make the animations work in testing. It gives 0 error or warning, but no animation is happening in testing :( |
@crisbeto how do we target the sass file generated by angular-cli instead? I have all my theming files there, so I should use that instead. |
Had the same issue here and manage to fix it by importing any of the themes in the karma.config file.
|
@herkulano @elvirdolic @farley911
But there was still the problem, that the import wasn't found when I ran I fixed it by replacing Now everything works as expected. Does anyone has an idea how to tell Karma how to import the correct file without this workaround above? |
@hpawe01 I had to do the same workaround for importing material theming, but everything works. Thanks for sharing your answer |
@hpawe01 's solution worked for me, although I did have to restart my 'npm test'. |
Some Material Components require some default styles. When setting up an angular application, you need to either create your own custom theme or include one of the default themes in order for these components to work. When testing, the whole application is not bootstrapped. Meaning the stylesheet(usually included in index.html of styles.(s)css) is not included, hence the warnings.
This includes the stylesheet in the final build |
@zessu IMHO, the issue is still valid, as it is not about the behavior being wrong, but about documenting it (I don't necessarily think that Getting Started should mention it, but it's not mentioned anywhere in the documentation, which seems to be an oversight to me). |
@hpawe01 did you have any issues with karma loading the assets under the "base" path? I can't get this working because of this. My styles.scss karma.conf I can add the files directly as @zessu said but I'll miss my custom styles.. plus adding twice the material styles sucks. |
@joaopgrassi: No, unfortunately I get the same warning as you get. It seems, that you have to add the path to the prebuild theme twice: in |
Well, mainly because I didn't want to add the styles twice which sucks. |
You can use the experimental
I don't think |
Thanks very much @yoonjesung - this is working. Now I can use the normal import in my
And it works without |
Bug, feature request, or proposal:
Bug or missing docs
What is the expected behavior?
Tests shouldn't log warnings after following the Getting Started guide on a fresh cli generated app.
Current behavior / steps to reproduce
md-card
component to AppComponentIs there anything else we should know?
Modifying
karma.conf.js
to include a theme silenced the warning. This approach was borrowed from Material's karma config:The text was updated successfully, but these errors were encountered: