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

Commit 7593a8a

Browse files
author
Kent C. Dodds
committed
Adding tests for #410
1 parent 4c526c5 commit 7593a8a

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

src/directives/formly-field.test.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -701,34 +701,52 @@ describe('formly-field', function() {
701701
);
702702
});
703703

704-
describe(`disabled`, () => {
705-
it(`should not do anything if the given instance is disabled`, () => {
706-
inputType.apiCheckInstance.config.disabled = true;
707-
scope.fields = [
708-
{type, templateOptions: {label: 'string'}}
709-
];
710-
shouldNotWarn(compileAndDigest);
711-
});
704+
describe(`apiCheckInstance`, () => {
705+
describe(`disabled`, () => {
706+
it(`should not do anything if the given instance is disabled`, () => {
707+
inputType.apiCheckInstance.config.disabled = true;
708+
scope.fields = [
709+
{type, templateOptions: {label: 'string'}}
710+
];
711+
shouldNotWarn(compileAndDigest);
712+
});
712713

713-
it(`should not do anything if no instance is provided and the formly instance is disabled`, inject((formlyApiCheck) => {
714-
formlyApiCheck.config.disabled = true;
715-
formlyConfig.setType({
716-
name: 'someOtherType',
717-
template: '<hr />',
718-
apiCheck: checker => ({data: {foo: checker.bool}})
714+
it(`should not do anything if no instance is provided and the formly instance is disabled`, inject((formlyApiCheck) => {
715+
formlyApiCheck.config.disabled = true;
716+
formlyConfig.setType({
717+
name: 'someOtherType',
718+
template: '<hr />',
719+
apiCheck: checker => ({data: {foo: checker.bool}})
720+
});
721+
scope.fields = [{type: 'someOtherType'}];
722+
shouldNotWarn(compileAndDigest);
723+
formlyApiCheck.config.disabled = false;
724+
}));
725+
726+
it(`should not do anything if the global instance is disabled`, () => {
727+
apiCheck.globalConfig.disabled = true;
728+
scope.fields = [
729+
{type, templateOptions: {label: 'string'}}
730+
];
731+
shouldNotWarn(compileAndDigest);
732+
apiCheck.globalConfig.disabled = false;
719733
});
720-
scope.fields = [{type: 'someOtherType'}];
721-
shouldNotWarn(compileAndDigest);
722-
formlyApiCheck.config.disabled = false;
723-
}));
734+
});
724735

725-
it(`should not do anything if the global instance is disabled`, () => {
726-
apiCheck.globalConfig.disabled = true;
727-
scope.fields = [
728-
{type, templateOptions: {label: 'string'}}
729-
];
730-
shouldNotWarn(compileAndDigest);
731-
apiCheck.globalConfig.disabled = false;
736+
describe.skip(`formlyConfig.extras.apiCheckInstance`, () => {
737+
it(`should default to this instance when specified and no specific type instance is specified`, () => {
738+
const globalApiCheckInstance = apiCheck({
739+
output: {prefix: 'custom-api-check'}
740+
});
741+
const warnSpy = sinon.spy(globalApiCheckInstance, 'warn');
742+
formlyConfig.extras.apiCheckInstance = globalApiCheckInstance;
743+
delete inputType.apiCheckInstance;
744+
scope.fields = [
745+
{type, templateOptions: {label: 'string', className: 'valid'}}
746+
];
747+
compileAndDigest();
748+
expect(warnSpy).to.have.been.calledOnce;
749+
});
732750
});
733751
});
734752

0 commit comments

Comments
 (0)