Skip to content

Commit ea8df35

Browse files
committed
test(user): expect the user store as the resolver's second argument
1 parent be213bd commit ea8df35

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/core/src/user/createUserStore.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ describe("createUserStore", () => {
2525
await userStore.loadUsers(["1", "2"]);
2626

2727
expect(resolveUsers).toHaveBeenCalledTimes(1);
28-
expect(resolveUsers).toHaveBeenCalledWith(["1", "2"]);
28+
// The store itself is passed as the second argument, so resolvers can
29+
// return synchronously and fill in more info via `setUser` later.
30+
expect(resolveUsers).toHaveBeenCalledWith(["1", "2"], userStore);
2931
expect(userStore.getUser("1")).toEqual(makeUser("1"));
3032
expect(userStore.getUser("2")).toEqual(makeUser("2"));
3133
expect(userStore.store.state.size).toBe(2);
@@ -40,7 +42,7 @@ describe("createUserStore", () => {
4042

4143
// Only the missing "3" should be requested the second time.
4244
expect(resolveUsers).toHaveBeenCalledTimes(2);
43-
expect(resolveUsers).toHaveBeenNthCalledWith(2, ["3"]);
45+
expect(resolveUsers).toHaveBeenNthCalledWith(2, ["3"], userStore);
4446

4547
await userStore.loadUsers(["1", "2", "3"]);
4648
// Everything cached now → no further requests.

packages/core/src/y/extensions/AttributionExtension.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ describe("AttributionExtension user loading", () => {
5858
addInsertMark(editor, ["alice"]);
5959

6060
expect(resolveUsers).toHaveBeenCalledTimes(1);
61-
expect(resolveUsers).toHaveBeenCalledWith(["alice"]);
61+
// The extension's user store passes itself as the resolver's second arg.
62+
expect(resolveUsers).toHaveBeenCalledWith(["alice"], expect.anything());
6263
});
6364

6465
it("does not load users for changes without attribution marks", () => {

0 commit comments

Comments
 (0)