nestjsx / nestjs-typeorm-paginate

:page_with_curl: Pagination response object function + types for typeorm + nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot mock paginate function

ApilPokhrel opened this issue · comments

import * as nestjsTypeormPaginate from 'nestjs-typeorm-paginate';

jest.spyOn(nestjsTypeormPaginate, 'paginate').mockImplementationOnce(() => Promise.resolve({items: [], meta: {}}))

Actual Behaviour
TypeError: Cannot redefine property: paginate
at Function.defineProperty ()

Expected Behaviour
{items: [], meta: {}}

Ok sorry, I've just found the issue related to your PR. I think this is an issue related to the default export? Have you tried mocking the packge method without the default export and have you tried to mock the import instead? I think that would be a better method.

const mockPaginateMethod = jest.fn()
jest.mock('nestjs-typeorm-paginate', () => ({
  ...jest.requireActual('nestjs-typeorm-paginate'),
  paginate: mockPaginateMethod,
}))


// somewhere else

mockPaginate.mockImplementationOnce(() => Promise.resolve({items: [], meta: {}}))

Actually yea, try that. That'll work