Skip to content

Should safe correct reactions order for changing depth without modification #12

Description

@betula
  test("should safe correct reactions order for changing depth without modification", () => {
    const spy = jest.fn();
    const a = mut(0);
    const b = mut(0);

    const m0 = comp(() => {
      return !b.val ? a.val : k0.val;
    });
    const k0 = comp(() => {
      return !b.val ? m0.val : a.val;
    });

    const m = comp(() => m0.val);
    const k = comp(() => k0.val);

    let i = 0;
    run(() => (k.val, spy('k', i++)));
    run(() => (m.val, spy('m', i++)));

    expect(spy).toHaveBeenNthCalledWith(1, 'k', 0);
    expect(spy).toHaveBeenNthCalledWith(2, 'm', 1);
    expect(spy).toBeCalledTimes(2);
    spy.mockReset();

    a.val = 1;
    expect(spy).toHaveBeenNthCalledWith(1, 'm', 2);
    expect(spy).toHaveBeenNthCalledWith(2, 'k', 3);
    expect(spy).toBeCalledTimes(2);
    spy.mockReset();

    // switch
    b.val = 1;
    expect(spy).toBeCalledTimes(0);

    // check
    a.val = 2;
    // TODO: check failed (m:4, k:5)
    // expect(spy).toHaveBeenNthCalledWith(1, 'k', 4);
    // expect(spy).toHaveBeenNthCalledWith(2, 'm', 5);
    expect(spy).toBeCalledTimes(2);
    spy.mockReset();
  });

d80be9c#diff-a9b84960a146958d9aecb5cbe3fccdf262c40fe07bddbb659f63d8a7766ed3a5R203-R245

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions