Hi All,
I am working on the Angular 2 Component Testing. My testing was
successfully working in RC 1 version but when I migrated it to final, it
provides error. My systemjs.config.js is as following
var map = {
"rxjs": "node_modules/rxjs",
"@angular/common": "node_modules/@angular/common",
"@angular/forms": "node_modules/@angular/forms",
"@angular/compiler": "node_modules/@angular/compiler",
"@angular/core": "node_modules/@angular/core",
"@angular/platform-browser": "node_modules/@angular/platform-browser",
"@angular/platform-browser-dynamic": "
node_modules/@angular/platform-browser-dynamic",
"@angular/core/testing":"node_modules/@angular/core/bundles",
};
var packages = {
"rxjs": { "defaultExtension": "js" },
"@angular/common": { "main": "bundles/common.umd.js", "defaultExtension":
"js" },
"@angular/forms": { "main": "bundles/forms.umd.js", "defaultExtension":
"js" },
"@angular/compiler": { "main": "bundles/compiler.umd.js",
"defaultExtension": "js" },
"@angular/core": { "main": "bundles/core.umd.js", "defaultExtension": "js"
},
"@angular/platform-browser": { "main": "bundles/platform-browser.umd.js",
"defaultExtension": "js" },
"@angular/platform-browser-dynamic": { "main":
"bundles/platform-browser-dynamic.umd.js", "defaultExtension": "js" },
'@angular/core/testing':{"main":"core-testing.umd.js", "defaultExtension":
"js"},
"app": {
format: 'register',
defaultExtension: 'js'
}
};
var config = {
map: map,
packages: packages
};
System.config(config);
My COmponent is as following (app.component.ts)
import {Component} from '@angular/core';
import {mathOperations} from './math.op';
@Component({
selector: 'math-op',
templateUrl: './app/app.html'
})
export class MathComponent {
mOP:mathOperations;
x:string;
y:string;
res:number
constructor() {
this.mOP= new mathOperations();
}
add(){
this.res = this.mOP.add(this.x,this.y);
}
sub(){
this.res = this.mOP.sub(this.x,this.y);
}
}
My TestCAse is as following (app.testet.ts)
import {inject,TestBed,ComponentFixture } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import {MathComponent} from './app.component';
describe('MathComponent', () => {
let app;
let x;
let y;
let res;
let fixture: ComponentFixture<MathComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MathComponent],
});
TestBed.compileComponents();
fixture = TestBed.createComponent(MathComponent);
app = fixture.componentInstance;
console.log('In describe');
});
it('addTest', () => {
x = "10";
y = "20";
res = 30;
app.x = x;
app.y = y;
fixture.detectChanges();
let actRes = app.add();
expect(actRes).toEqual(res);
});
});
The Html file for test is as following (testui.html)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Ng App Unit Tests</title>
<link rel="stylesheet"
href="./node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script
src="./node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script
src="./node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script
src="./node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/zone.js/dist/long-stack-trace-zone.js"></script>
<script src="node_modules/zone.js/dist/async-test.js"></script>
<script src="node_modules/zone.js/dist/fake-async-test.js"></script>
<script src="node_modules/zone.js/dist/sync-test.js"></script>
<script src="node_modules/zone.js/dist/proxy.js"></script>
<script src="node_modules/zone.js/dist/jasmine-patch.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
</head>
<body>
<script src="systemjs.config.js"></script>
<script>
Promise.all([
System.import('@angular/core/testing'),
System.import('./app/app.tester.spec')
])
// System.import('./app/app.component.spec')
.then(window.onload)
.catch(console.error.bind(console));
</script>
</body>
</html>
<https://lh3.googleusercontent.com/-BgiwApDQvD8/V-JveVxJD_I/AAAAAAAAAG4/xkThBF-0SMkn_PeBdqLwThdBgSVaDTrngCLcB/s1600/error_21_sept.PNG>
I am not understanding whats really going wrong. It will be great if
anybody solve this.
Thanks in Advance.
Regards
Mahesh Sabnis
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.