0

测试应该检查是否使用当前用户 ID 调用inbox.get12345以获取currentuser过滤条件

当我运行测试时,它无法进入return(dispatch, getstate),我仅在此处添加的两个控制台日志中Console.log(--------test 1-----------)正在打印。第二个不是。所以我认为问题在于我如何嘲笑dispatchgetState

代码:

function loadInboxSummary(paginationOffset) 
  Console.log(--------test 1-----------);
  {return (dispatch, getState) => {
    Console.log(--------testing inside 2 ---------);
    const state = getState();
    const userId = getCurrentUserId(state);
    const filterCriteria = getCurrentFilter(state);

    const adjustedInboxViewFilter = {
      ...filterCriteria,
      assignedUserIds: mapCurrentAssignee(userId),
    };

    return InboxItems.get(
      userId,
      adjustedInboxViewFilter,
      paginationOffset,
    ) ................

在调用 InboxItems.get(..) 时进行测试,它具有正确的参数来调整 InboxView。

测试:

describe("loadInboxSummary", () => {
  const dispatch = jest.fn();
  const getState = jest.fn().mockReturnValue("mock_state");

  beforeEach(() => {
    jest.spyOn(getCurrentUserDetails, "getCurrentUserId").mockReturnValue("12345");
    jest.spyOn(getCurrentFilter, "default").mockReturnValue({assignedUserIds: ["currentUser"]});
    jest.spyOn(InboxItems, "get").mockResolvedValue({});
  });

  it("calls InboxItems.get with current user id", () => {
    loadInboxSummary("mock_pagination")(dispatch, getState);
    const adjustedFilters = {
      assignedUserIds: ["12345"],
    };

    expect(InboxItems.get).toHaveBeenCalledWith(
      "12345",
      adjustedFilters,
      "mock_pagination",
    ); }); });
Error: expect(jest.fn()).toHaveBeenCalledWith(...expected)
Expected: "12345", {"assignedUserIds": ["12345"]}, "mock_pagination"
Number of calls: 0

这是我第一次进行前端测试,我搜索了堆栈溢出以寻找可能的解决方案,但它们看起来完全不同/具有异步功能,所以我无法理解它们。非常感谢一些帮助。不确定是什么导致了这个错误,所以请随时提问。

4

0 回答 0