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

Commit 3bba183

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/directives/formly-field.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,40 @@ describe('formly-field', function() {
13211321
});
13221322

13231323
describe(`options.validation.errorExistsAndShouldBeVisible`, () => {
1324+
describe.skip(`multiple ng-model elements`, () => {
1325+
beforeEach(() => {
1326+
scope.fields = [
1327+
{
1328+
template: `
1329+
<input ng-model="model[options.data.firstKey]" />
1330+
<input ng-model="model[options.data.secondKey]" />
1331+
`,
1332+
// we'll just give it a validator that depends on a value we
1333+
// can change in our tests
1334+
validators: {foo: '!options.data.invalid'}
1335+
}
1336+
];
1337+
});
1338+
1339+
it(`should set showError to true when one of them is invalid`, () => {
1340+
compileAndDigest();
1341+
expect(field.validation.errorExistsAndShouldBeVisible, 'initially false').to.be.false;
1342+
field.data.invalid = true;
1343+
1344+
// force $touched and revalidation of both form controls
1345+
field.formControl.forEach(fc => {
1346+
fc.$setTouched();
1347+
fc.$validate();
1348+
});
1349+
1350+
// redigest to set the showError prop
1351+
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+
});
1356+
});
1357+
13241358
describe(`with custom errorExistsAndShouldBeVisible expression`, () => {
13251359
beforeEach(() => {
13261360
scope.fields = [getNewField({validators: {foo: 'false'}})];

0 commit comments

Comments
 (0)