diff --git a/packages/xml/test/decorators.test.ts b/packages/xml/test/decorators.test.ts index 3fe91e83a5..8c18107454 100644 --- a/packages/xml/test/decorators.test.ts +++ b/packages/xml/test/decorators.test.ts @@ -11,12 +11,14 @@ beforeEach(async () => { }); describe("@name", () => { - it("set the value via encodedName", async () => { - const { Blob } = (await runner.compile(`@test @Xml.name("XmlBlob") model Blob {}`)) as { - Blob: Model; - }; - - expect(resolveEncodedName(runner.program, Blob, "application/xml")).toEqual("XmlBlob"); + it.each([ + ["model", `@test @Xml.name("XmlName") model Blob {}`], + ["model prop", `model Blob {@Xml.name("XmlName") @test title:string}`], + ["scalar", `@Xml.name("XmlName") @test scalar Blob extends string;`], + ])("%s", async (_, code) => { + const result = await runner.compile(`${code}`); + const curr = (result.Blob || result.title) as Model; + expect(resolveEncodedName(runner.program, curr, "application/xml")).toEqual("XmlName"); }); }); @@ -153,6 +155,19 @@ describe("@ns", () => { }); }); + it("emit error if missing the 2nd argument", async () => { + const diagnostics = await runner.diagnose(` + model Blob { + @Xml.ns("https://example.com/ns1") id : string; + } + `); + + expectDiagnostics(diagnostics, { + code: "@typespec/xml/ns-missing-prefix", + message: "When using a string namespace you must provide a prefix as the 2nd argument.", + }); + }); + it("emit error if providing prefix param with enum member namespace", async () => { const diagnostics = await runner.diagnose(` @Xml.nsDeclarations