когда я импортирую класс из модуля
const { OAuth2Client } = require('google-auth-library');
Как я могу это высмеять?
jest.mock("google-auth-library"); // not mocking directly OAuth2Client
jest.mock("google-auth-library", OAuth2Client ) // is incorrect
И если я добавлю онлайн-реализацию, у меня нет классаимя
jest.mock("google-auth-library", () => {
return jest.fn().mockImplementation(() => {
return {
setCredentials: setCredentialsMock,
getAccessToken: getAccessTokenMock
}
})
});
, поэтому я не могу вызвать конструктор:
const oAuth2Client = new OAuth2Client({...});
Обратная связь приветствуется
ОБНОВЛЕНИЕ 1 -
Вот наиболее важная кодировка из google-auth-library-nodejs, связанная с моей проблемой
google-auth-library-nodejs module
============================================= /src/auth/index.ts ...export {.., OAuth2Client, ...} из './auth/oauth2client';... const auth = new GoogleAuth ();export {auth, GoogleAuth};
=======================================
/src/auth/oauth2client.js
import {AuthClient} from './authclient';
...
export class OAuth2Client extends AuthClient {
....
constructor(clientId?: string, clientSecret?: string, redirectUri?: string);
constructor(
...
super();
...
this._clientId = opts.clientId;
this._clientSecret = opts.clientSecret;
this.redirectUri = opts.redirectUri;
...
}
...
getAccessToken(): Promise<GetAccessTokenResponse>;
...
}
====================================== /src/auth/authclient.ts
import {Credentials} from './credentials';
...
export abstract class AuthClient extends EventEmitter {
...
setCredentials(credentials: Credentials) {
this.credentials = credentials;
}
}
======================================== /src/auth/credentials.js
export interface Credentials {
refresh_token?: string|null;
expiry_date?: number|null;
access_token?: string|null;
token_type?: string|null;
id_token?: string|null;
}
...