scottrippey / next-router-mock

Mock implementation of the Next.js Router
MIT License
400 stars 38 forks source link

BUG: Adding scroll option cause test to fail #127

Open garryismael opened 1 week ago

garryismael commented 1 week ago

When i test my custom hooks, it failed after adding scroll options. If i remove it, the test passed

export const useFilter = () => {
  const router = useRouter();
  const pathname = usePathname();
  const searchParams = useSearchParams();
  const search = searchParams.get("search");

  const clearFilter = () => {
    router.push(pathname, {
      scroll: false,
    });
  };

  const createQueryString = useCallback(
    (name, value) => {
      const params = new URLSearchParams(searchParams.toString());
      params.set(name, value);
      return params.toString();
    },
    [searchParams]
  );

  const changeSearchQuery = (key, value) => {
    router.push(pathname + "?" + createQueryString(key, value), {
      scroll: false,
    });
  };

  return { search, changeSearchQuery, clearFilter };
};