typescript Ejemplo de测试路由
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Ejemplo de测试路由相关的知识,希望对你有一定的参考价值。
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import { HomeComponent } from './home.component';
import {RouterTestingModule} from '@angular/router/testing';
import {By} from '@angular/platform-browser';
import {routes} from '../../routes';
import {Location} from '@angular/common';
import {Router} from '@angular/router';
import {ThemeListComponent} from '../theme-list/theme-list.component';
import {CardComponent} from '../card-list/card/card.component';
describe('HomeComponent', () => {
let location: Location;
let router: Router;
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent, ThemeListComponent, CardComponent ],
imports: [
RouterTestingModule.withRoutes(routes)
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should have an h1 tag with text "Bienvenido"', () => {
const h1Element = fixture.debugElement.query(By.css('h1')).nativeElement;
expect(h1Element.innerText).toEqual('Bienvenido');
});
// Routing
it('should navigate to /themes when themes button is clicked', fakeAsync( () => {
fixture.debugElement.queryAll(By.css('button'))[0].triggerEventHandler('click', null);
tick();
expect(location.path()).toBe('/themes');
}));
});
以上是关于typescript Ejemplo de测试路由的主要内容,如果未能解决你的问题,请参考以下文章
typescript Ejemplo测试异步
text ejemplo de vue
java Ejemplo de Java 8
PHP ejemplo de AJAX
PHP ejemplo de AJAX
xml Ejemplo del XML de curvas de nivel 100k