This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('not be able to get data', async(() => { | |
mockBackend.connections.subscribe( | |
(connection: MockConnection) => { | |
connection.mockError(new Error()); | |
}); | |
service.getData().subscribe(data => data, | |
error => { | |
expect(error.toString()).toContain('Something went wrong. Please try again later.'); | |
}); | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import {MockBackend, MockConnection} from '@angular/http/testing'; | |
//import {BaseRequestOptions, Http, Headers, ResponseOptions, Response} from '@angular/http'; | |
it('be able to get data', () => { | |
mockBackend.connections.subscribe( | |
(connection: MockConnection) => { | |
connection.mockRespond(new Response( | |
new ResponseOptions({ | |
body: [{name : 'Jerry'},{name : 'George'},{name : 'Elaine'},{name : 'Kramer'}], | |
status: 200, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
providers: [ | |
AppService, | |
MockBackend, | |
BaseRequestOptions, | |
{ | |
provide: Http, | |
useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { | |
return new Http(backend, defaultOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('get initialized', () => expect(service).toBeDefined() ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
providers: [AppService] | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Headers, Http} from '@angular/http'; | |
import {Injectable, Inject} from '@angular/core'; | |
import {Observable} from 'rxjs/Observable'; | |
import 'rxjs/add/observable/of'; | |
import 'rxjs/add/observable/throw'; | |
import 'rxjs/add/operator/catch'; | |
import 'rxjs/add/operator/map'; | |
@Injectable() | |
export class AppService { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child extends Component { | |
constructor() { | |
super(); | |
} | |
handleChangeEvent() { | |
this.props.onNameChange('Heisenberg') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App extends Component { | |
constructor() { | |
super() | |
this.state = {name: 'Say my name'} | |
} | |
handleName(newName) { | |
this.setState({ name: newName}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class MyComponent extends Component { | |
constructor() { | |
super(); | |
this.state= {name: 'Say my name'}; | |
setInterval( | |
() => { | |
this.setState({name: 'Heisenberg'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child extends Component { | |
render() { | |
return ( | |
<h1>{this.props.name}</h1> | |
); | |
} | |
} |
NewerOlder