Skip to content

Commit

Permalink
test: mock diagnosticProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Oct 12, 2023
1 parent 3ad286e commit 860bde2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/analytics-browser/test/helpers/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Logger, MemoryStorage, UUID } from '@amplitude/analytics-core';
import { BrowserClient, BrowserConfig, LogLevel, UserSession } from '@amplitude/analytics-types';
import { BrowserDiagnostic } from '../../src/diagnostics/diagnostic';

export const createAmplitudeMock = (): jest.MockedObject<BrowserClient> => ({
init: jest.fn(),
Expand Down Expand Up @@ -79,7 +78,12 @@ export const createConfigurationMock = (options?: Partial<BrowserConfig>) => {
},
trackingSessionEvents: false,
userId: undefined,
diagnosticProvider: new BrowserDiagnostic(),
diagnosticProvider: {
isDisabled: false,
serverUrl: undefined,
apiKey: undefined,
track: jest.fn(),
},
...options,
};
};
1 change: 1 addition & 0 deletions packages/analytics-core/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('config', () => {
apiKey: API_KEY,
storageProvider: defaultConfig.storageProvider,
transportProvider: defaultConfig.transportProvider,
diagnosticProvider: defaultConfig.diagnosticProvider,
});
expect(config).toEqual({
apiKey: 'apiKey',
Expand Down
10 changes: 7 additions & 3 deletions packages/analytics-core/test/helpers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Config } from '@amplitude/analytics-types';
import { getDefaultConfig } from '../../src/config';

export const useDefaultConfig = (): Config => {
const defaultConfig = getDefaultConfig();
defaultConfig.diagnosticProvider.apiKey = API_KEY;
return {
apiKey: API_KEY,
transportProvider: {
Expand All @@ -17,7 +15,13 @@ export const useDefaultConfig = (): Config => {
reset: async () => undefined,
getRaw: async () => undefined,
},
...defaultConfig,
...getDefaultConfig(),
diagnosticProvider: {
isDisabled: false,
serverUrl: undefined,
apiKey: undefined,
track: jest.fn(),
},
};
};

Expand Down

0 comments on commit 860bde2

Please sign in to comment.