浏览代码

Update `addSchema` comments, new test.

Afshin Darian 7 年之前
父节点
当前提交
8842f604f4
共有 2 个文件被更改,包括 14 次插入0 次删除
  1. 2 0
      packages/coreutils/src/settingregistry.ts
  2. 12 0
      test/src/coreutils/settingregistry.spec.ts

+ 2 - 0
packages/coreutils/src/settingregistry.ts

@@ -329,10 +329,12 @@ class DefaultSchemaValidator implements ISchemaValidator {
     const validator = this._validator;
     const validate = validator.getSchema('main');
 
+    // Validate against the main schema.
     if (!(validate(schema) as boolean)) {
       return validate.errors as ISchemaValidator.IError[];
     }
 
+    // Validate against the JSON schema meta-schema.
     if (!(validator.validateSchema(schema) as boolean)) {
       return validator.errors as ISchemaValidator.IError[];
     }

+ 12 - 0
test/src/coreutils/settingregistry.spec.ts

@@ -73,6 +73,18 @@ describe('@jupyterlab/coreutils', () => {
         expect(errors).to.not.be(null);
       });
 
+      it('should be safe to call multiple times', () => {
+        const validator = new DefaultSchemaValidator();
+        const plugin = 'foo';
+        const schema = { type: 'object' };
+
+        let errors = validator.addSchema(plugin, schema);
+
+        expect(errors).to.be(null);
+        errors = validator.addSchema(plugin, schema);
+        expect(errors).to.be(null);
+      });
+
     });
 
   });