microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-missing-extension-methods

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/asset-emitter/test/object-builder.test.ts

48lines · modecode

1import { beforeEach, describe, expect, it } from "vitest";
2import { ObjectBuilder } from "../src/index.js";
3import { Placeholder } from "../src/placeholder.js";
4
5describe("ObjectBuilder", () => {
6 it("create simple builder", () => {
7 const builder = new ObjectBuilder({
8 foo: "bar",
9 });
10 expect(builder.foo).toBe("bar");
11 });
12
13 it("create adds elements to builder", () => {
14 const builder = new ObjectBuilder({
15 foo: "bar",
16 });
17 builder.set("bar", "baz");
18 expect(builder.foo).toBe("bar");
19 expect(builder.bar).toBe("baz");
20 });
21
22 describe("when working with placeholders", () => {
23 let placeholder: Placeholder<any>;
24
25 beforeEach(() => {
26 placeholder = new Placeholder();
27 });
28
29 it("has no values to start with", () => {
30 const builder = new ObjectBuilder(placeholder);
31 expect(builder.foo).toBeUndefined();
32 });
33
34 it("resolve values from placeholder", () => {
35 const builder = new ObjectBuilder(placeholder);
36 expect(builder.foo).toBeUndefined();
37 placeholder.setValue({ foo: "bar" });
38 expect(builder.foo).toBe("bar");
39 });
40
41 it("create object builder from another object builder with a placeholder", () => {
42 const builder1 = new ObjectBuilder(placeholder);
43 const builder2 = new ObjectBuilder(builder1);
44 placeholder.setValue({ foo: "bar" });
45 expect(builder2.foo).toBe("bar");
46 });
47 });
48});
49