mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +03:00
The production bundle mangles class names, so unrelated models in separate chunks (eg User/WebhookSubscription, Collection/Pin) shared one @Field list. Adds a lint rule against reading constructor.name in client code.
25 lines
801 B
TypeScript
25 lines
801 B
TypeScript
import type Model from "../base/Model";
|
|
import Field, { getFieldsForModelClass } from "./Field";
|
|
|
|
describe("Field", () => {
|
|
it("records fields on the decorated class", () => {
|
|
class Example {}
|
|
Field(Example.prototype as Model, "name");
|
|
Field(Example.prototype as Model, "color");
|
|
|
|
expect(getFieldsForModelClass(Example)).toEqual(["name", "color"]);
|
|
});
|
|
|
|
it("does not leak fields between classes that share a name", () => {
|
|
// Minified builds can mangle two unrelated classes to the same name.
|
|
const One = class Model {};
|
|
const Two = class Model {};
|
|
|
|
Field(One.prototype as Model, "name");
|
|
Field(Two.prototype as Model, "index");
|
|
|
|
expect(getFieldsForModelClass(One)).toEqual(["name"]);
|
|
expect(getFieldsForModelClass(Two)).toEqual(["index"]);
|
|
});
|
|
});
|