Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
Javascript testing: Mocking dispatch and get state

The test should be checking if inbox.get is getting called with current user id 12345 for currentuser filter criteria.

When I run the tests, it's not able to enter return(dispatch, getstate), out of the two console logs that i added here only Console.log(--------test 1-----------) is being printed. Second one is not. So im thinking that the problem is with how im mocking dispatch and getState.

Code:

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,
    ) ................

Testing when InboxItems.get(..) is called, it has correct parameters for adjustedInboxView.

Test:

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

This is my first time doing front end testing, I searched stack overflow for possible solutions but they looked quite different/had async functions so I couldn't understand them. Would really appreciate some help. Not sure what could be causing this error so feel free to ask questions.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!