當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mixins.applyMixins函數代碼示例

本文整理匯總了TypeScript中models/mixins/mixins.applyMixins函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript applyMixins函數的具體用法?TypeScript applyMixins怎麽用?TypeScript applyMixins使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了applyMixins函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

    it("should be invalid if associated attributes are invalid", () => {
      //tslint:disable-next-line
      interface Material extends ValidatableMixin {
      }

      class Material implements ValidatableMixin {
        url: Stream<string>;

        constructor(url: string) {
          ValidatableMixin.call(this);
          this.url = stream(url);
          this.validatePresenceOf("url");
        }
      }

      applyMixins(Material, ValidatableMixin);

      //tslint:disable-next-line
      interface Task extends ValidatableMixin {
      }

      class Task implements ValidatableMixin {
        command: Stream<string>;

        constructor(command: string) {
          ValidatableMixin.call(this);
          this.command = stream(command);
          this.validatePresenceOf("command");
        }
      }

      applyMixins(Task, ValidatableMixin);

      //tslint:disable-next-line
      interface Pipeline extends ValidatableMixin {
      }

      class Pipeline implements ValidatableMixin {
        material: Stream<Material>;
        task: Stream<Task>;

        constructor(material: Material, task: Task) {
          ValidatableMixin.call(this);
          this.material = stream(material);
          this.task     = stream(task);
          this.validateAssociated("material");
          this.validateAssociated("task");
        }
      }

      applyMixins(Pipeline, ValidatableMixin);

      const pipeline = new Pipeline(new Material(""), new Task("some command"));
      expect(pipeline.isValid()).toBe(false);
      expect(pipeline.errors().hasErrors()).toBe(false);
      expect(pipeline.material().errors().hasErrors()).toBe(true);
      expect(pipeline.task().errors().hasErrors()).toBe(false);
    });
開發者ID:Skarlso,項目名稱:gocd,代碼行數:58,代碼來源:new_validatable_mixin_spec.ts

示例2: describe

  describe("validateUrlPattern", () => {
    //tslint:disable-next-line
    interface Material extends ValidatableMixin {
    }

    class Material implements ValidatableMixin {
      url: Stream<string>;

      constructor(url: string) {
        ValidatableMixin.call(this);
        this.url = stream(url);
        this.validateUrlPattern("url");
      }
    }

    applyMixins(Material, ValidatableMixin);

    it("should validate url pattern", () => {
      const material = new Material("ftp://some.com");

      material.validate();

      expect(material.errors().hasErrors()).toBe(true);
      expect(material.errors().errors("url")).toEqual(["Url must be a valid http(s) url"]);
    });

    it("should skip validation for empty attribute", () => {
      const material = new Material("");

      material.validate();

      expect(material.errors().hasErrors()).toBe(false);
    });
  });
開發者ID:Skarlso,項目名稱:gocd,代碼行數:34,代碼來源:new_validatable_mixin_spec.ts

示例3: it

    it("should validate Id format", () => {
      //tslint:disable-next-line
      interface Material extends ValidatableMixin {
      }

      class Material implements ValidatableMixin {
        id: Stream<string>;

        constructor(id: string) {
          ValidatableMixin.call(this);
          this.id = stream(id);
          this.validateIdFormat("id");
        }
      }

      applyMixins(Material, ValidatableMixin);

      const badStrings = ["shaky salamander", ".hello", _.repeat("a", 256)];
      badStrings.forEach((badString) => {
        const material = new Material(badString);
        material.validate();
        expect(material.errors().hasErrors()).toBe(true);
        expect(material.errors().errors("id"))
          .toEqual(["Invalid id. This must be alphanumeric and can contain hyphens, underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."]);
      });

    });
開發者ID:GaneshSPatil,項目名稱:gocd,代碼行數:27,代碼來源:new_validatable_mixin_spec.ts


注:本文中的models/mixins/mixins.applyMixins函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。