Repository: solidjs/solid
File: packages/solid/test/signals.spec.ts (TypeScript)

Code before:
      setTimeout(() => {
        expect(temp).toBe("unpure thoughts");
        setSign("mind");
        expect(temp).toBe("unpure mind");
        done();
      });
    });
  });
  test("Create and trigger an Effect with function signals", done => {
    createRoot(() => {
      let temp: string;
      const [sign, setSign] = createSignal<() => string>(() => "thoughts");
      createEffect(() => (temp = `unpure ${sign()()}`));
      setTimeout(() => {
        expect(temp).toBe("unpure thoughts");
        setSign(() => () => "mind");
        expect(temp).toBe("unpure mind");
        done();
      });
    });
  });
  test("Set signal returns argument", () => {
    const [_, setValue] = createSignal<number>();
    const res1: number | undefined = setValue(undefined);
    expect(res1).toBe(undefined);
    const res2: number | undefined = setValue(12);
    expect(res2).toBe(12);
    const res3 = setValue(Math.random() >= 0 ? 12 : undefined);
    expect(res3).toBe(12);
    const res4 = setValue();
    expect(res4).toBe(undefined);
  });
});

describe("Untrack signals", () => {
  test("Mute an effect", done => {
    createRoot(() => {
      let temp: string;
      const [sign, setSign] = createSignal("thoughts");
      createEffect(() => (temp = `unpure ${untrack(sign)}`));
      setTimeout(() => {
        expect(temp).toBe("unpure thoughts");
        setSign("mind");
        expect(temp).toBe("unpure thoughts");
        done();
      });
    });
  });
});

describe("Batch signals", () => {

Review comment (bug):
Oh, um, this change. Hmmmmm. Maybe it wasn't a bug fix like my commit message thought.

Code after:
      setTimeout(() => {
        expect(temp).toBe("unpure thoughts");
        setSign("mind");
        expect(temp).toBe("unpure mind");
        done();
      });
    });
  });
  test("Create and trigger an Effect with function signals", done => {
    createRoot(() => {
      let temp: string;
      const [sign, setSign] = createSignal<() => string>(() => "thoughts");
      createEffect(() => (temp = `unpure ${sign()()}`));
      setTimeout(() => {
        expect(temp).toBe("unpure thoughts");
        setSign(() => () => "mind");
        expect(temp).toBe("unpure mind");
        done();
      });
    });
  });
  test("Set signal returns argument", () => {
    const [_, setValue] = createSignal<number>();
    const res1: undefined = setValue(undefined);
    expect(res1).toBe(undefined);
    const res2: number = setValue(12);
    expect(res2).toBe(12);
    const res3 = setValue(Math.random() >= 0 ? 12 : undefined);
    expect(res3).toBe(12);
    const res4 = setValue();
    expect(res4).toBe(undefined);
  });
});

describe("Untrack signals", () => {
  test("Mute an effect", done => {
    createRoot(() => {
      let temp: string;
      const [sign, setSign] = createSignal("thoughts");
      createEffect(() => (temp = `unpure ${untrack(sign)}`));
      setTimeout(() => {
        expect(temp).toBe("unpure thoughts");
        setSign("mind");
        expect(temp).toBe("unpure thoughts");
        done();
      });
    });
  });
});

describe("Batch signals", () => {