UNPKG

@benshi.ai/js-sdk

Version:

Benshi SDK

74 lines (60 loc) 1.98 kB
/** * @jest-environment jsdom */ import Feed from "." import BsCore from "../../core/BsCore"; import { ContentBlock } from "../Navigation/typings"; import { ProfileAction, ProfileListType, ProfileType, SocialTypes } from "./typings"; let windowSpy let mockSender; let mockImpressionManager describe('ELearning', () => { beforeAll(() => { mockSender = { add() { return false } } }) beforeEach(() => { windowSpy = jest.spyOn(window, "window", "get"); }) afterEach(() => { // to remove the singleton instance (BsCore as any).instance = null }) it('Should deliver a "Profile" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false, ContentBlock.Core,'device-id') const event = { type: ProfileType.User, action: ProfileAction.View, profile_id: '123', } Feed.logProfileEvent(event) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: SocialTypes.Profile, props: event }), expect.anything()) }) it('Should deliver a "ProfileList" event', () => { const senderSpy = jest.spyOn(mockSender, 'add') const bsCore = BsCore.createInstance(mockSender as any, mockImpressionManager as any, false,ContentBlock.Core, 'device-id') const event = { type: ProfileListType.Followers, } Feed.logProfileListEvent(event) expect(senderSpy).toBeCalledWith( expect.anything(), expect.anything(), expect.objectContaining( { type: SocialTypes.ProfileList, props: event }), expect.anything()) }) })