I seem to have misunderstood something and now I am confused. I could really use some guidance, please.
Currently, I am utilizing the Gitbeaker
API in my Node.js code as I write tests. However, I am encountering failures with the following errors:
ReferenceError: requesterFn must be passed
In my code, I have initialized the API client as follows:
import { Gitlab } from '@gitbeaker/core'
...
const gitLabApi: Gitlab<false> = await createGitLabApi(repoId)
I believe I should be using the @gitbeaker/rest
, but when I attempt to do so, the TypeScript compiler does not approve of the above code:
'Gitlab' refers to a value, but is being used as a type here. Did you mean 'typeof Gitlab'?
Therefore, I opted to utilize the core package.
The function createGitLabApi
looks like this:
import { Gitlab } from '@gitbeaker/core'
import RepositoryModel from '../models/repository/repositoryModel'
const createGitLabApi = async (repoId: number): Promise<Gitlab<false>> => {
const repository = await RepositoryModel.findByPk(repoId)
if (!repository)
throw new Error(`The repository ID [${repoId}] doesn't exist in database!`)
return new Gitlab({
token: repository.token ?? '',
host: repository.host
})
}
export default createGitLabApi
I wish to pass this created API client to functions so that only one client is generated but multiple calls can be initiated.
In my test scenario, I have the following setup:
const mockedGitLabApi = jest.mocked(new Gitlab({host: '', token: ''}), {shallow: true})
const projects: GitLabProjectType[] = await getGitLabProjects(mockedGitLabApi, path);
(I am still figuring out how to create a mock object of Gitlab
to pass it to my getGitLabProjects
function and specify different mock responses for this mock, but that's a separate issue)
However, when I run the test, I encounter the error message:
ReferenceError: requesterFn must be passed
83 |
> 84 | const mockedGitLabApi = jest.mocked(new Gitlab({host: '', token: ''}), {shallow: true})
I assume I should be using @gitbeaker/rest
, but then TypeScript complains, and I am unable to set the type of the API client as Gitlab
->
'Gitlab' refers to a value, but is being used as a type here. Did you mean 'typeof Gitlab'?
So, currently, I am somewhat uncertain about how to initialize the Gitbeaker API client. Any hints, please?