forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HttpClient API upgrade instead of deprecated Http (PatrickJS#1923)
* HttpClient API upgrade instead of deprecated Http * Fix for e2e tests as well as package-lock.json added for npm users (yarn is slow on windows)
- Loading branch information
Showing
8 changed files
with
12,491 additions
and
66 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
import { | ||
inject, | ||
TestBed | ||
async, | ||
TestBed, | ||
ComponentFixture, | ||
getTestBed | ||
} from '@angular/core/testing'; | ||
import { Component } from '@angular/core'; | ||
import { | ||
BaseRequestOptions, | ||
ConnectionBackend, | ||
Http | ||
} from '@angular/http'; | ||
import { MockBackend } from '@angular/http/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { Title } from './title.service'; | ||
|
||
describe('Title', () => { | ||
beforeEach(() => TestBed.configureTestingModule({ | ||
providers: [ | ||
BaseRequestOptions, | ||
MockBackend, | ||
{ | ||
provide: Http, | ||
useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => { | ||
return new Http(backend, defaultOptions); | ||
}, | ||
deps: [MockBackend, BaseRequestOptions] | ||
}, | ||
Title | ||
]})); | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [Title] | ||
}); | ||
}); | ||
|
||
it('should have http', inject([ Title ], (title: Title) => { | ||
it('should have http', inject([Title], (title: Title) => { | ||
expect(!!title.http).toEqual(true); | ||
})); | ||
|
||
it('should get data from the server', inject([ Title ], (title: Title) => { | ||
it('should get data from the server', inject([Title], (title: Title) => { | ||
spyOn(console, 'log'); | ||
expect(console.log).not.toHaveBeenCalled(); | ||
|
||
title.getData(); | ||
expect(console.log).toHaveBeenCalled(); | ||
expect(title.getData()).toEqual({ value: 'AngularClass' }); | ||
title.getData().subscribe( (result) => { | ||
expect(result).toEqual({ value: 'AngularClass' }); | ||
}); | ||
})); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Http } from '@angular/http'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
@Injectable() | ||
export class Title { | ||
|
||
public value = 'Angular 2'; | ||
|
||
constructor( | ||
public http: Http | ||
) {} | ||
public http: HttpClient | ||
) { } | ||
|
||
public getData() { | ||
console.log('Title#getData(): Get Data'); | ||
/** | ||
* return this.http.get('/assets/data.json') | ||
* .map(res => res.json()); | ||
*/ | ||
return { | ||
value: 'AngularClass' | ||
}; | ||
return this.http.get('/assets/data.json'); | ||
} | ||
|
||
} |
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