@@ -1339,8 +1339,23 @@ describe('formly-field', function() {
1339
1339
it ( `should set showError to true when one of them is invalid` , ( ) => {
1340
1340
compileAndDigest ( ) ;
1341
1341
expect ( field . validation . errorExistsAndShouldBeVisible , 'initially false' ) . to . be . false ;
1342
- field . data . invalid = true ;
1342
+ invalidateAndTouchFields ( ) ;
1343
+
1344
+ expect ( field . formControl [ 0 ] . $error . foo , '$error on the first formControl' ) . be . true ;
1345
+ expect ( field . validation . errorExistsAndShouldBeVisible , 'now true' ) . to . be . true ;
1346
+ } ) ;
1347
+
1348
+ it ( `should work with a custom errorExistsAndShouldBeVisibleExpression` , ( ) => {
1349
+ const spy = sinon . spy ( ) ;
1350
+ formlyConfig . extras . errorExistsAndShouldBeVisibleExpression = spy ;
1351
+ compileAndDigest ( ) ;
1343
1352
1353
+ invalidateAndTouchFields ( ) ;
1354
+ expect ( spy ) . to . have . been . calledWith ( sinon . match . array , sinon . match . array ) ;
1355
+ } ) ;
1356
+
1357
+ function invalidateAndTouchFields ( ) {
1358
+ field . data . invalid = true ;
1344
1359
// force $touched and revalidation of both form controls
1345
1360
field . formControl . forEach ( fc => {
1346
1361
fc . $setTouched ( ) ;
@@ -1349,10 +1364,7 @@ describe('formly-field', function() {
1349
1364
1350
1365
// redigest to set the showError prop
1351
1366
scope . $digest ( ) ;
1352
-
1353
- expect ( field . formControl [ 0 ] . $error . foo , '$error on the first formControl' ) . be . true ;
1354
- expect ( field . validation . errorExistsAndShouldBeVisible , 'now true' ) . to . be . true ;
1355
- } ) ;
1367
+ }
1356
1368
} ) ;
1357
1369
1358
1370
describe ( `with custom errorExistsAndShouldBeVisible expression` , ( ) => {
0 commit comments