karma-runner / karma-runner/karma
Unable to run unit tests using ng test with Angular projects with Polymer elements
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
### Expected behaviour
We should be able to run unit test using Angular CLI
### Actual behaviour
In debug browser, a test that passes according to the command line fails in the debug browser with error message: [object ErrorEvent] thrown.
### Environment Details
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/platform-server": "^5.0.0",
"@angular/router": "^5.0.0",
"@angular/service-worker": "^1.0.0-beta.16",
"@codebakery/origami": "^2.0.0-alpha.2",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.5.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"codelyzer": "~3.2.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"polymer-webpack-loader": "^2.0.0",
"protractor": "~5.1.2",
"script-loader": "^0.7.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "2.4.2"
}
- Karma version (output of `karma --version`):
- Relevant part of your `karma.config.js` file
ustomLaunchers: {
Chrome_with_debugging: {
base: 'Chrome',
flags: ['--remote-debugging-port=9222'],
debug: true
}
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
### Steps to reproduce the behaviour
1. run unit tests on an angular project with polymer used https://github.com/hotforfeature/angular-polymer-starter-kit
2. With minimal changes I could see Jasmine started running the unit tests after adding CUSTOM_ELEMENTS_SCHEMA & importing RouterTestingModule.
import { TestBed, async } from '/testing';
import { AppComponent } from './app.component';
import { RouterTestingModule } from '/testing';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA} from '';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
imports: [RouterTestingModule],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.overrideComponent(AppComponent, {
set: {
template: ''
}}).createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
3. On running ng test:
After this change I started seeing the error:
Unit test: AppComponent should create the app
[object ErrorEvent] thrown
[object ErrorEvent] thrown
[object ErrorEvent] thrown
[object ErrorEvent] thrown
[object ErrorEvent] thrown
[object ErrorEvent] thrown
[object ErrorEvent] thrown
Error: Expected undefined to equal 'app'.
at stack (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:2176:17)
at buildExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:2146:14)
at Spec.expectationResultFactory (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:766:18)
at Spec.addExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:444:34)
at Expectation.addExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:710:21)
at Expectation.toEqual (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?da99c5b057693d025fad3d7685e1590600ca376d:2099:12)
at Object.eval (webpack:///D:/PLM_TE/17._Angular2/NgPolyPotractor/angular-polymer-starter-kit-master/src/app/app.component.spec.ts?:33:27)
at ZoneDelegate.invoke (webpack:///D:/PLM_TE/17._Angular2/NgPolyPotractor/angular-polymer-starter-kit-master/node_modules/zone.js/dist/zone.js?:388:26)
at AsyncTestZoneSpec.onInvoke (webpack:///D:/PLM_TE/17._Angular2/NgPolyPotractor/angular-polymer-starter-kit-master/node_modules/zone.js/dist/async-test.js?:49:39)
at ProxyZoneSpec.onInvoke (webpack:///D:/PLM_TE/17._Angular2/NgPolyPotractor/angular-polymer-starter-kit-master/node_modules/zone.js/dist/proxy.js?:76:39)
It looks like Polymer elements are null and unable to initialize the component. But I couldn't get any more information. Any idea what I am missing that Jasmine expects.
I tried disabling source_maps as mentioned here, angular/angular-cli#7296 but that also didn't work. [ng test --sm=false]
Regards
Basanth
Contributor guide
Research direction
Start by reproducing the issue with ng test in the angular-polymer-starter-kit project, then inspect the reported AppComponent spec and the relevant karma.config.js settings. Compare the command-line result with the Chrome debug browser and use the [object ErrorEvent] output to identify why the Polymer elements are unavailable; done means the test passes consistently in the debug browser.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, javascript
- Domain
- frontend, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100