Skip to content

Commit 7249af0

Browse files
committed
Merge pull request #101 from nsanitate/master
fix(npm): Updated to beta 16
2 parents e95bc66 + a49888f commit 7249af0

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

bundles/ng2-translate.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ System.registerDynamic("src/translate.pipe", ["angular2/core", "./translate.serv
8080
_this._ref.markForCheck();
8181
});
8282
};
83-
TranslatePipe.prototype.transform = function(query, args) {
83+
TranslatePipe.prototype.transform = function(query) {
8484
var _this = this;
85+
var args = [];
86+
for (var _i = 1; _i < arguments.length; _i++) {
87+
args[_i - 1] = arguments[_i];
88+
}
8589
if (!query || query.length === 0) {
8690
return query;
8791
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"angular2": ">= 2.0.0-beta.10"
3131
},
3232
"devDependencies": {
33-
"angular2": "2.0.0-beta.15",
33+
"angular2": "2.0.0-beta.16",
3434
"commitizen": "~2.5.0",
3535
"cz-conventional-changelog": "~1.1.4",
3636
"es6-promise": "^3.0.2",

src/translate.pipe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class TranslatePipe implements PipeTransform, OnDestroy {
7575
});
7676
}
7777

78-
transform(query: string, args: any[]): any {
78+
transform(query: string, ...args: any[]): any {
7979
if(!query || query.length === 0) {
8080
return query;
8181
}

tests/translate.pipe.spec.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {TranslatePipe} from '../src/translate.pipe';
22
import {MockConnection, MockBackend} from "angular2/src/http/backends/mock_backend";
33
import {TRANSLATE_PROVIDERS, TranslateService} from "./../ng2-translate";
44
import {ResponseOptions, Response, XHRBackend, HTTP_PROVIDERS} from "angular2/http";
5-
import {provide, Injector, ChangeDetectorRef} from "angular2/core";
5+
import {provide, Injector, ReflectiveInjector, ChangeDetectorRef} from "angular2/core";
66
import {LangChangeEvent} from "../src/translate.service";
77

88
class FakeChangeDetectorRef extends ChangeDetectorRef {
@@ -31,7 +31,7 @@ export function main() {
3131
let ref: any;
3232

3333
beforeEach(() => {
34-
injector = Injector.resolveAndCreate([
34+
injector = ReflectiveInjector.resolveAndCreate([
3535
HTTP_PROVIDERS,
3636
// Provide a mocked (fake) backend for Http
3737
provide(XHRBackend, {useClass: MockBackend}),
@@ -65,31 +65,31 @@ export function main() {
6565
translate.setTranslation('en', {"TEST": "This is a test"});
6666
translate.use('en');
6767

68-
expect(translatePipe.transform('TEST', [])).toEqual("This is a test");
68+
expect(translatePipe.transform('TEST')).toEqual("This is a test");
6969
});
7070

7171
it('should call markForChanges when it translates a string', () => {
7272
translate.setTranslation('en', {"TEST": "This is a test"});
7373
translate.use('en');
7474
spyOn(ref, 'markForCheck').and.callThrough();
7575

76-
translatePipe.transform('TEST', []);
76+
translatePipe.transform('TEST');
7777
expect(ref.markForCheck).toHaveBeenCalled();
7878
});
7979

8080
it('should translate a string with object parameters', () => {
8181
translate.setTranslation('en', {"TEST": "This is a test {{param}}"});
8282
translate.use('en');
8383

84-
expect(translatePipe.transform('TEST', [{param: "with param"}])).toEqual("This is a test with param");
84+
expect(translatePipe.transform('TEST', {param: "with param"})).toEqual("This is a test with param");
8585
});
8686

8787
it('should translate a string with object as string parameters', () => {
8888
translate.setTranslation('en', {"TEST": "This is a test {{param}}"});
8989
translate.use('en');
9090

91-
expect(translatePipe.transform('TEST', ['{param: "with param"}'])).toEqual("This is a test with param");
92-
expect(translatePipe.transform('TEST', ['{"param": "with param"}'])).toEqual("This is a test with param");
91+
expect(translatePipe.transform('TEST', '{param: "with param"}')).toEqual("This is a test with param");
92+
expect(translatePipe.transform('TEST', '{"param": "with param"}')).toEqual("This is a test with param");
9393
});
9494

9595
it('should update the value when the parameters change', () => {
@@ -99,11 +99,11 @@ export function main() {
9999
spyOn(translatePipe, 'updateValue').and.callThrough();
100100
spyOn(ref, 'markForCheck').and.callThrough();
101101

102-
expect(translatePipe.transform('TEST', [{param: "with param"}])).toEqual("This is a test with param");
102+
expect(translatePipe.transform('TEST', {param: "with param"})).toEqual("This is a test with param");
103103
// same value, shouldn't call 'updateValue' again
104-
expect(translatePipe.transform('TEST', [{param: "with param"}])).toEqual("This is a test with param");
104+
expect(translatePipe.transform('TEST', {param: "with param"})).toEqual("This is a test with param");
105105
// different param, should call 'updateValue'
106-
expect(translatePipe.transform('TEST', [{param: "with param2"}])).toEqual("This is a test with param2");
106+
expect(translatePipe.transform('TEST', {param: "with param2"})).toEqual("This is a test with param2");
107107
expect(translatePipe.updateValue).toHaveBeenCalledTimes(2);
108108
expect(ref.markForCheck).toHaveBeenCalledTimes(2);
109109
});
@@ -114,7 +114,7 @@ export function main() {
114114
let param = 'param: "with param"';
115115

116116
expect(() => {
117-
translatePipe.transform('TEST', [param]);
117+
translatePipe.transform('TEST', param);
118118
}).toThrowError(`Wrong parameter in TranslatePipe. Expected a valid Object, received: ${param}`)
119119
});
120120

@@ -124,12 +124,12 @@ export function main() {
124124
translate.setTranslation('fr', {"TEST": "C'est un test"});
125125
translate.use('en');
126126

127-
expect(translatePipe.transform('TEST', [])).toEqual("This is a test");
127+
expect(translatePipe.transform('TEST')).toEqual("This is a test");
128128

129129
// this will be resolved at the next lang change
130130
translate.onLangChange.subscribe((res: LangChangeEvent) => {
131131
expect(res.lang).toEqual('fr');
132-
expect(translatePipe.transform('TEST', [])).toEqual("C'est un test");
132+
expect(translatePipe.transform('TEST')).toEqual("C'est un test");
133133
done();
134134
});
135135

@@ -139,12 +139,12 @@ export function main() {
139139
it('with file loader', (done) => {
140140
translate.use('en');
141141
mockBackendResponse(connection, '{"TEST": "This is a test"}');
142-
expect(translatePipe.transform('TEST', [])).toEqual("This is a test");
142+
expect(translatePipe.transform('TEST')).toEqual("This is a test");
143143

144144
// this will be resolved at the next lang change
145145
translate.onLangChange.subscribe((res: LangChangeEvent) => {
146146
expect(res.lang).toEqual('fr');
147-
expect(translatePipe.transform('TEST', [])).toEqual("C'est un test");
147+
expect(translatePipe.transform('TEST')).toEqual("C'est un test");
148148
done();
149149
});
150150

tests/translate.service.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {it} from "angular2/testing";
2-
import {provide, Injector} from "angular2/core";
2+
import {provide, Injector, ReflectiveInjector} from "angular2/core";
33
import {ResponseOptions, Response, HTTP_PROVIDERS, XHRBackend} from "angular2/http";
44
import {MockBackend, MockConnection} from "angular2/http/testing";
55
import {
@@ -24,7 +24,7 @@ export function main() {
2424
let connection: MockConnection; // this will be set when a new connection is emitted from the backend.
2525

2626
beforeEach(() => {
27-
injector = Injector.resolveAndCreate([
27+
injector = ReflectiveInjector.resolveAndCreate([
2828
HTTP_PROVIDERS,
2929
// Provide a mocked (fake) backend for Http
3030
provide(XHRBackend, {useClass: MockBackend}),
@@ -261,7 +261,7 @@ export function main() {
261261
}
262262

263263
let prepare = ((handlerClass: Function) => {
264-
injector = Injector.resolveAndCreate([
264+
injector = ReflectiveInjector.resolveAndCreate([
265265
HTTP_PROVIDERS,
266266
// Provide a mocked (fake) backend for Http
267267
provide(XHRBackend, {useClass: MockBackend}),
@@ -419,7 +419,7 @@ export function main() {
419419
};
420420

421421
it('should be able to provide TranslateStaticLoader', () => {
422-
injector = Injector.resolveAndCreate([
422+
injector = ReflectiveInjector.resolveAndCreate([
423423
HTTP_PROVIDERS,
424424
// Provide a mocked (fake) backend for Http
425425
provide(XHRBackend, {useClass: MockBackend}),
@@ -449,7 +449,7 @@ export function main() {
449449
return Observable.of({"TEST": "This is a test"});
450450
}
451451
}
452-
injector = Injector.resolveAndCreate([
452+
injector = ReflectiveInjector.resolveAndCreate([
453453
HTTP_PROVIDERS,
454454
// Provide a mocked (fake) backend for Http
455455
provide(XHRBackend, {useClass: MockBackend}),

0 commit comments

Comments
 (0)