本文整理汇总了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);
});
示例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);
});
});
示例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."]);
});
});