angularjs - How to test my RouteConfig and other decorators in an Angular 2 Component -
i trying write unit tests angular 2 component before go further have no idea how write test checks whether routeconfig's path set '/documents'. have test verifies template contains <router-outlet></router-outlet>
inside.
this component:
import { component } 'angular2/core'; import { canactivate, routeconfig, router_directives } angular2/router'; import documentscomponent './documents/documents.component'; @component({ template: ` dashboard <router-outlet></router-outlet> `, directives: [ router_directives, ] }) @canactivate((next, prev) => { // check if user has access return true; }) @routeconfig([ { path: '/documents', name: 'documents', component: documentscomponent, useasdefault: true, } ]) export default class dashboardcomponent { public name: string = 'john'; sayhello(): string { return `hello ${this.name}`; } }
and test (i'm using jasmine):
import dashboardcomponent './../app/dashboard/dashboard.component'; import {describe, it, beforeeach, expect} 'angular2/testing'; describe('my dashboardcomponent', () => { var dashboard: dashboardcomponent = null; beforeeach(function() { dashboard = new dashboardcomponent(); }); it('should have path set "/documents"', function() { // ??? }); it('should have "<router-outlet></router-outlet>" in template', function() { // ??? }); it('should have name property', function() { expect(dashboard.name).tobe('john'); }); it('should hello name property', function() { expect(dashboard.sayhello()).tobe('hello john'); }); });
in case haven't found answers yet: https://medium.com/google-developer-experts/angular-2-unit-testing-with-jasmine-defe20421584#.13taw92p0
Comments
Post a Comment