Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 0a3f411

Browse files
author
Kent C. Dodds
committed
test(formly-field): Add more tests for #510
1 parent 3bba183 commit 0a3f411

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/directives/formly-field.test.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,8 +1339,23 @@ describe('formly-field', function() {
13391339
it(`should set showError to true when one of them is invalid`, () => {
13401340
compileAndDigest();
13411341
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();
13431352

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;
13441359
// force $touched and revalidation of both form controls
13451360
field.formControl.forEach(fc => {
13461361
fc.$setTouched();
@@ -1349,10 +1364,7 @@ describe('formly-field', function() {
13491364

13501365
// redigest to set the showError prop
13511366
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+
}
13561368
});
13571369

13581370
describe(`with custom errorExistsAndShouldBeVisible expression`, () => {

0 commit comments

Comments
 (0)