当前位置: 首页>>代码示例>>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;未经允许,请勿转载。