I am trying to test this service. As you can see, mixpanel is not an injected service. It is an imported namespace.
import * as mixpanel from 'mixpanel-browser';
@Injectable({
providedIn: 'root',
})
export class MixpanelService {
constructor() {
mixpanel.init('xxxxxxxx');
}
public register(value: string): void {
mixpanel.register(value);
}
}
describe('MixpanelService', () => { let service: MixpanelService;
beforeEach(async() => {
TestBed.configureTestingModule({
providers: [
//mixpanel is not an injected service...
]
});
service = TestBed.inject(MixpanelService);
});
it('should call register method', () => {
//Arrange
let mockMixPanel = ??? //how to mock a namespace????
let spyOnRegister = jest.spyOn(mockMixPanel, 'register');
//Act
service.register({});
//Assert
expect(spyOnRegister).toHaveBeenCalled();
});
}
Thanks for helping