I'm having trouble understanding what is going on with the .spec.ts tests that are automatically generated in Angular. They each include expect(component).toBeTruthy();
, which to my understanding is a very simple test to check if the component was created. But roughly half of them pass and half fail, and I cannot see any rhyme or reason as to why.
Here is an example from a header element that I can very clearly see on every single view of the app:
Error: Expected undefined to be truthy.
at <Jasmine>
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/header-page/header-page.component.spec.ts:24:23)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:364:1)
at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:292:1)
Whereas other components have what appears to be the same test, and they pass their tests for 'should create' or 'should create an instance'.
I am working through the Angular docs, but I can't find any place to start with this. Why would automatically generated tests fail? Should I be looking at each test individually? Does it makes a difference if that component is currently showing on the client's screen or not? Should I be looking at settings in the karma.conf.js file? The project runs fine with no errors. What parts of the code could I include in this post to help you answer my question?
Aucun commentaire:
Enregistrer un commentaire