@@ -146,6 +146,57 @@ describe('ngPluralize', function() {
146
146
} ) ) ;
147
147
} ) ;
148
148
149
+ describe ( 'undefined rule cases' , function ( ) {
150
+ var $locale , $log ;
151
+ beforeEach ( inject ( function ( _$locale_ , _$log_ ) {
152
+ $locale = _$locale_ ;
153
+ $log = _$log_ ;
154
+ } ) ) ;
155
+ afterEach ( inject ( function ( $log ) {
156
+ $log . reset ( ) ;
157
+ } ) ) ;
158
+
159
+ it ( 'should generate a warning when being asked to use a rule that is not defined' ,
160
+ inject ( function ( $rootScope , $compile ) {
161
+ element = $compile (
162
+ '<ng:pluralize count="email"' +
163
+ "when=\"{'0': 'Zero'," +
164
+ "'one': 'Some text'," +
165
+ "'other': 'Some text'}\">" +
166
+ '</ng:pluralize>' ) ( $rootScope ) ;
167
+ $locale . pluralCat = function ( ) { return "few" ; } ;
168
+
169
+ $rootScope . email = '3' ;
170
+ expect ( $log . debug . logs ) . toEqual ( [ ] ) ;
171
+ $rootScope . $digest ( ) ;
172
+ expect ( element . text ( ) ) . toBe ( '' ) ;
173
+ expect ( $log . debug . logs . shift ( ) )
174
+ . toEqual ( [ "ngPluralize: no rule defined for 'few' in {'0': 'Zero','one': 'Some text','other': 'Some text'}" ] ) ;
175
+ } ) ) ;
176
+
177
+ it ( 'should empty the element content when using a rule that is not defined' ,
178
+ inject ( function ( $rootScope , $compile ) {
179
+ element = $compile (
180
+ '<ng:pluralize count="email"' +
181
+ "when=\"{'0': 'Zero'," +
182
+ "'one': 'Some text'," +
183
+ "'other': 'Some text'}\">" +
184
+ '</ng:pluralize>' ) ( $rootScope ) ;
185
+ $locale . pluralCat = function ( count ) { return count === 1 ? "one" : "few" ; } ;
186
+
187
+ $rootScope . email = '0' ;
188
+ $rootScope . $digest ( ) ;
189
+ expect ( element . text ( ) ) . toBe ( 'Zero' ) ;
190
+
191
+ $rootScope . email = '3' ;
192
+ $rootScope . $digest ( ) ;
193
+ expect ( element . text ( ) ) . toBe ( '' ) ;
194
+
195
+ $rootScope . email = '1' ;
196
+ $rootScope . $digest ( ) ;
197
+ expect ( element . text ( ) ) . toBe ( 'Some text' ) ;
198
+ } ) ) ;
199
+ } ) ;
149
200
150
201
describe ( 'deal with pluralized strings with offset' , function ( ) {
151
202
it ( 'should show single/plural strings with offset' , inject ( function ( $rootScope , $compile ) {
0 commit comments