-
-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TranslateService): Reverted the use of Injector and changed Angul…
…ar 2 requirement to ~beta.0 ins It was not a good idea to use the Injector to load Http, the real problem was that Ionic 2 uses Angular 2 beta.0 and ng2-translate uses Angular 2 beta.1. The ionic 2 cli was packaging 2 different instances of Angular 2 and ng2-translate couldn't get Http because the provider it used wasn't the same as the one from the main Ionic 2 application. Changing the requirement to ~beta.0 fixes that problem.
- Loading branch information
Showing
4 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
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,9 +1,46 @@ | ||
import {it, beforeEachProviders, inject} from "angular2/testing"; | ||
import {provide} from "angular2/core"; | ||
import { | ||
BaseRequestOptions, Http, ResponseOptions, Response, HTTP_PROVIDERS, Connection, | ||
XHRBackend | ||
} from "angular2/http"; | ||
import {MockBackend, MockConnection} from "angular2/http/testing"; | ||
import {TranslateService} from '../src/translate.service'; | ||
|
||
export function main() { | ||
|
||
describe('TranslateService', () => { | ||
beforeEachProviders(() => [ | ||
BaseRequestOptions, | ||
HTTP_PROVIDERS, | ||
// Provide a mocked (fake) backend for Http | ||
provide(XHRBackend, {useClass: MockBackend}), | ||
TranslateService | ||
]); | ||
|
||
|
||
it('is defined', () => { | ||
expect(TranslateService).toBeDefined(); | ||
}); | ||
|
||
// this test is async, and yet it works thanks to Zone \o/ | ||
it('should be able to get translations for the view', inject([XHRBackend, Http, TranslateService], (xhrBackend, http, translate) => { | ||
var connection: MockConnection; //this will be set when a new connection is emitted from the backend. | ||
xhrBackend.connections.subscribe((c: MockConnection) => connection = c); | ||
|
||
// this will load translate json files from src/public/i18n | ||
translate.useStaticFilesLoader(); | ||
|
||
// the lang to use, if the lang isn't available, it will use the current loader to get them | ||
translate.use('en'); | ||
|
||
// this will request the translation from the backend because we use a static files loader for TranslateService | ||
translate.get('TEST').subscribe((res: string) => { | ||
expect(res).toEqual('This is a test'); | ||
}); | ||
|
||
// mock response after the xhr request, otherwise it will be undefined | ||
connection.mockRespond(new Response(new ResponseOptions({body: '{"TEST": "This is a test"}'}))); | ||
})); | ||
}); | ||
} |