diff --git a/spec/unit/NamespacedValue.spec.ts b/spec/unit/NamespacedValue.spec.ts index 834acd0c9fa..d2864a134b4 100644 --- a/spec/unit/NamespacedValue.spec.ts +++ b/spec/unit/NamespacedValue.spec.ts @@ -21,18 +21,21 @@ describe("NamespacedValue", () => { const ns = new NamespacedValue("stable", "unstable"); expect(ns.name).toBe(ns.stable); expect(ns.altName).toBe(ns.unstable); + expect(ns.names).toEqual([ns.stable, ns.unstable]); }); it("should return unstable if there is no stable", () => { const ns = new NamespacedValue(null, "unstable"); expect(ns.name).toBe(ns.unstable); expect(ns.altName).toBeFalsy(); + expect(ns.names).toEqual([ns.unstable]); }); it("should have a falsey unstable if needed", () => { const ns = new NamespacedValue("stable", null); expect(ns.name).toBe(ns.stable); expect(ns.altName).toBeFalsy(); + expect(ns.names).toEqual([ns.stable]); }); it("should match against either stable or unstable", () => { @@ -58,12 +61,14 @@ describe("UnstableValue", () => { const ns = new UnstableValue("stable", "unstable"); expect(ns.name).toBe(ns.unstable); expect(ns.altName).toBe(ns.stable); + expect(ns.names).toEqual([ns.unstable, ns.stable]); }); it("should return unstable if there is no stable", () => { const ns = new UnstableValue(null, "unstable"); expect(ns.name).toBe(ns.unstable); expect(ns.altName).toBeFalsy(); + expect(ns.names).toEqual([ns.unstable]); }); it("should not permit falsey unstable values", () => { diff --git a/src/NamespacedValue.ts b/src/NamespacedValue.ts index 59c2a1f830e..794366f8b32 100644 --- a/src/NamespacedValue.ts +++ b/src/NamespacedValue.ts @@ -41,6 +41,13 @@ export class NamespacedValue { return this.unstable; } + public get names(): (U | S)[] { + const names = [this.name]; + const altName = this.altName; + if (altName) names.push(altName); + return names; + } + public matches(val: string): boolean { return this.name === val || this.altName === val; }