@@ -2,7 +2,7 @@ import {TranslatePipe} from '../src/translate.pipe';
2
2
import { MockConnection , MockBackend } from "angular2/src/http/backends/mock_backend" ;
3
3
import { TRANSLATE_PROVIDERS , TranslateService } from "./../ng2-translate" ;
4
4
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" ;
6
6
import { LangChangeEvent } from "../src/translate.service" ;
7
7
8
8
class FakeChangeDetectorRef extends ChangeDetectorRef {
@@ -31,7 +31,7 @@ export function main() {
31
31
let ref : any ;
32
32
33
33
beforeEach ( ( ) => {
34
- injector = Injector . resolveAndCreate ( [
34
+ injector = ReflectiveInjector . resolveAndCreate ( [
35
35
HTTP_PROVIDERS ,
36
36
// Provide a mocked (fake) backend for Http
37
37
provide ( XHRBackend , { useClass : MockBackend } ) ,
@@ -65,31 +65,31 @@ export function main() {
65
65
translate . setTranslation ( 'en' , { "TEST" : "This is a test" } ) ;
66
66
translate . use ( 'en' ) ;
67
67
68
- expect ( translatePipe . transform ( 'TEST' , [ ] ) ) . toEqual ( "This is a test" ) ;
68
+ expect ( translatePipe . transform ( 'TEST' ) ) . toEqual ( "This is a test" ) ;
69
69
} ) ;
70
70
71
71
it ( 'should call markForChanges when it translates a string' , ( ) => {
72
72
translate . setTranslation ( 'en' , { "TEST" : "This is a test" } ) ;
73
73
translate . use ( 'en' ) ;
74
74
spyOn ( ref , 'markForCheck' ) . and . callThrough ( ) ;
75
75
76
- translatePipe . transform ( 'TEST' , [ ] ) ;
76
+ translatePipe . transform ( 'TEST' ) ;
77
77
expect ( ref . markForCheck ) . toHaveBeenCalled ( ) ;
78
78
} ) ;
79
79
80
80
it ( 'should translate a string with object parameters' , ( ) => {
81
81
translate . setTranslation ( 'en' , { "TEST" : "This is a test {{param}}" } ) ;
82
82
translate . use ( 'en' ) ;
83
83
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" ) ;
85
85
} ) ;
86
86
87
87
it ( 'should translate a string with object as string parameters' , ( ) => {
88
88
translate . setTranslation ( 'en' , { "TEST" : "This is a test {{param}}" } ) ;
89
89
translate . use ( 'en' ) ;
90
90
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" ) ;
93
93
} ) ;
94
94
95
95
it ( 'should update the value when the parameters change' , ( ) => {
@@ -99,11 +99,11 @@ export function main() {
99
99
spyOn ( translatePipe , 'updateValue' ) . and . callThrough ( ) ;
100
100
spyOn ( ref , 'markForCheck' ) . and . callThrough ( ) ;
101
101
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" ) ;
103
103
// 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" ) ;
105
105
// 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" ) ;
107
107
expect ( translatePipe . updateValue ) . toHaveBeenCalledTimes ( 2 ) ;
108
108
expect ( ref . markForCheck ) . toHaveBeenCalledTimes ( 2 ) ;
109
109
} ) ;
@@ -114,7 +114,7 @@ export function main() {
114
114
let param = 'param: "with param"' ;
115
115
116
116
expect ( ( ) => {
117
- translatePipe . transform ( 'TEST' , [ param ] ) ;
117
+ translatePipe . transform ( 'TEST' , param ) ;
118
118
} ) . toThrowError ( `Wrong parameter in TranslatePipe. Expected a valid Object, received: ${ param } ` )
119
119
} ) ;
120
120
@@ -124,12 +124,12 @@ export function main() {
124
124
translate . setTranslation ( 'fr' , { "TEST" : "C'est un test" } ) ;
125
125
translate . use ( 'en' ) ;
126
126
127
- expect ( translatePipe . transform ( 'TEST' , [ ] ) ) . toEqual ( "This is a test" ) ;
127
+ expect ( translatePipe . transform ( 'TEST' ) ) . toEqual ( "This is a test" ) ;
128
128
129
129
// this will be resolved at the next lang change
130
130
translate . onLangChange . subscribe ( ( res : LangChangeEvent ) => {
131
131
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" ) ;
133
133
done ( ) ;
134
134
} ) ;
135
135
@@ -139,12 +139,12 @@ export function main() {
139
139
it ( 'with file loader' , ( done ) => {
140
140
translate . use ( 'en' ) ;
141
141
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" ) ;
143
143
144
144
// this will be resolved at the next lang change
145
145
translate . onLangChange . subscribe ( ( res : LangChangeEvent ) => {
146
146
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" ) ;
148
148
done ( ) ;
149
149
} ) ;
150
150
0 commit comments