Skip to content

Commit

Permalink
Merge branch 'main' into 04-consecutive-updates-take2
Browse files Browse the repository at this point in the history
  • Loading branch information
stocaaro committed Jan 5, 2024
2 parents 10ccded + 483bf03 commit 965c5b5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
49 changes: 46 additions & 3 deletions packages/core/__tests__/Hub.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Hub } from '../src';
import { Hub, AMPLIFY_SYMBOL } from '../src/Hub';
import { ConsoleLogger } from '../src';

describe('Hub', () => {
const loggerSpy = jest.spyOn(ConsoleLogger.prototype, '_log');

afterEach(() => {
loggerSpy.mockClear();
});

test('happy case', () => {
const listener = jest.fn(() => {});

Expand All @@ -23,7 +29,6 @@ describe('Hub', () => {

test('Protected channel', () => {
const listener = jest.fn(() => {});
const loggerSpy = jest.spyOn(ConsoleLogger.prototype, '_log');

Hub.listen('auth', listener);

Expand All @@ -46,7 +51,6 @@ describe('Hub', () => {

test('Protected channel - ui', () => {
const listener = jest.fn(() => {});
const loggerSpy = jest.spyOn(ConsoleLogger.prototype, '_log');

Hub.listen('ui', listener);

Expand Down Expand Up @@ -97,4 +101,43 @@ describe('Hub', () => {

expect(listener).not.toHaveBeenCalled();
});

describe('Symbol fallback when not supported', () => {
const originalSymbol = global.Symbol;

beforeAll(() => {
global.Symbol = undefined as any;
jest.resetModules();
});

afterAll(() => {
global.Symbol = originalSymbol;
});

it('works with Symbol fallback', () => {
const mockListener = jest.fn();

const {
Hub: HubInstance,
AMPLIFY_SYMBOL: amplifySymbolValue,
} = require('../src/Hub');

expect(amplifySymbolValue).toStrictEqual('@@amplify_default');

HubInstance.listen('auth', mockListener);

HubInstance.dispatch(
'auth',
{
event: 'signOut',
data: 'the user has been signed out',
message: 'User signout has taken place',
},
'Auth',
amplifySymbolValue
);

expect(loggerSpy).not.toHaveBeenCalled();
});
});
});
30 changes: 0 additions & 30 deletions packages/core/__tests__/HubClass.test.ts

This file was deleted.

0 comments on commit 965c5b5

Please sign in to comment.