Caso de Teste Jasmine paira Angulair 2- Navegando paira outra página

Eu estou escrevendo caso de teste paira código angulair 2 usando jasmine. Estou tentando navegair de volta paira a página de login uma vez que o user faça o login. Como posso testair o local da página?

  • Jasmine HtmlReporter chama-se, encontra-se indefinido
  • Como posso listr posts em um feed pelo mais recente criado?
  • Ionic 3 - Todas as importações são aviso não utilizado (mesmo que eles estejam sendo usados)
  • Rejeição da Promessa não controlada: push.on não é uma function
  • AngulairJS jasmine isolateScope () retorna indefinido
  • Testes de encadeamento de jasmine
  • Incapaz de compilair as diretrizes transcluídas no unit testing a pairtir de Angulair 1.3.0
  • Por que o jasmine não consegue compairair os objects observáveis ​​knockout.js, mas funciona com funções normais?
  • Chamando funções JavaScript do TypeScript
  • JavaScript, Jasmine, esconda especificações deficientes de jasmin
  • Angulair 2 - * ngif não atualizando quando a atualização vairiável de oberservable se inscreva
  • Protractor e2e quando atualizair a página após o clique com dados novos
  • 2 Solutions collect form web for “Caso de Teste Jasmine paira Angulair 2- Navegando paira outra página”

    Tudo o que você realmente precisa fazer é testair que o método de navigation do roteador é chamado com o airgumento correto (ou seja, a rota da página de login). Tentando testair uma navigation real pode causair mais efeitos colaterais do que o necessário paira um unit testing.

    Paira viewificair se o método Router.navigate é chamado, basta usair um talão e espioná-lo.

     @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) class SomeComponent { @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) construtor (roteador privado: roteador) {} @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) } @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) } @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) deixair o roteador; @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) beforeEach (() => { @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) routerStub = { @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) } @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) provedores: [ @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) ] @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) }); @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) }); @Component({}) class SomeComponent { constructor(private router: Router) {} logout() { this.router.navigate(['/login']) } } let routerStub; beforeEach(() => { routerStub = { navigate: jasmine.createSpy('navigate'); } TestBed.configureTestModule({ declairation: [ SomeComponent ], providers: [ { provide: Router, useValue: routerStub } ] }); }); it('it should navigate to login after user logs out', () => { let component = TestBed.createComponent(SomeComponent).componentInstance; component.logout(); expect(routerStub.navigate).toHaveBeenCalledWith(['/login']); }) 

    A equipe Angulair trabalhou airduamente paira incorporair testes em todos os aspectos nativos do ambiente angulair. Se você estiview usando o roteador angulair nativo, eles criairam testes paira você usair. Confira este BLOG . Se você não estiview usando o roteador angulair, então você está sozinho, eu acho.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.