Created
September 8, 2023 01:19
-
-
Save mandemeskel/f46721081faac61ec766f10b8ada5733 to your computer and use it in GitHub Desktop.
create one place where all your mocks are created
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import JestMockers from "@tests/jest_mockers" | |
import { Database } from "firebase/database" | |
namespace FirebaseMocks { | |
export function createAppInitMock() { | |
const app_mock = jest.fn() | |
const initializeAppMock = jest.fn() | |
initializeAppMock.mockReturnValue(app_mock) | |
JestMockers.mockDefaultExport( | |
'firebase/app', | |
{ | |
initializeApp: initializeAppMock, | |
} | |
) | |
return { | |
app_mock, | |
initializeAppMock, | |
} | |
} | |
export function createMockDb() : { | |
actual: Database, | |
mock: { app: jest.Mock, type: jest.Mock }, | |
} { | |
const mock = { app: jest.fn(), type: jest.fn() } | |
const actual = mock | |
// @ts-ignore mock of app is not complete | |
return { actual, mock } | |
} | |
export function mockAnalytics() { | |
const getAnalyticsMock = jest.fn() | |
const logEventMock = jest.fn() | |
JestMockers.mockDefaultExport( | |
'firebase/analytics', | |
{ | |
getAnalytics: getAnalyticsMock, | |
logEvent: logEventMock, | |
} | |
) | |
return { | |
getAnalyticsMock, | |
logEventMock, | |
} | |
} | |
export function mockClientDatabase() { | |
const getDatabaseMock = jest.fn() | |
const goOfflineMock = jest.fn() | |
JestMockers.mockDefaultExport( | |
'firebase/database', | |
{ | |
getDatabase: getDatabaseMock, | |
goOffline: goOfflineMock, | |
} | |
) | |
return { | |
getDatabaseMock, | |
goOfflineMock, | |
} | |
} | |
} | |
export default FirebaseMocks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment