How to use the ts-mockito.mock function in ts-mockito

To help you get started, we’ve selected a few ts-mockito examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moribellamy / graytabby / tests / mockBrowserContainer.ts View on Github external
when(this.browser.extension).thenReturn(instance(this.extension));
    when(this.extension.getURL).thenReturn(s => s);

    this.tabs = mock();
    when(this.browser.tabs).thenReturn(instance(this.tabs));

    this.storage = mock();
    when(this.browser.storage).thenReturn(instance(this.storage));

    this.localStorage = mock();
    when(this.storage.local).thenReturn(instance(this.localStorage));

    this.runtime = mock();
    when(this.browser.runtime).thenReturn(instance(this.runtime));

    this.onMessage = mock();
    this.listeners = [];
    when(this.runtime.onMessage).thenReturn(instance(this.onMessage));
    when(this.onMessage.addListener).thenReturn(toAdd => this.listeners.push(toAdd));
    when(this.onMessage.removeListener).thenReturn(toRemove =>
      snip(this.listeners, l => l == toRemove),
    );
    when(this.runtime.sendMessage).thenReturn((message: any) => {
      this.listeners.map(l => l(message));
      return Promise.resolve();
    });

    this.setTabs([]);
    this.setTabGroups([]);
    this.setOptions({ tabLimit: 100, archiveDupes: false, homeGroup: [] });
  }
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / app / settings / settings.component.spec.ts View on Github external
class TestProject extends SFProject {
  static readonly TYPE = 'project';

  constructor(init?: Partial) {
    super(init);
    this.projectName = 'project01';
  }
}

class TestEnvironment {
  component: SettingsComponent;
  fixture: ComponentFixture;
  overlayContainer: OverlayContainer;

  isLoading: boolean = false;
  mockedActivatedRoute: ActivatedRoute = mock(ActivatedRoute);
  mockedAuthService: AuthService = mock(AuthService);
  mockedNoticeService: NoticeService = mock(NoticeService);
  mockedParatextService: ParatextService = mock(ParatextService);
  mockedSFProjectService: SFProjectService = mock(SFProjectService);
  mockedUserService: UserService = mock(UserService);

  private readonly project$: BehaviorSubject>;
  private readonly paratectProjects$: BehaviorSubject;

  constructor() {
    when(this.mockedActivatedRoute.params).thenReturn(of({ projectId: 'project01' }));
    when(this.mockedNoticeService.isLoading).thenCall(() => this.isLoading);
    this.paratectProjects$ = new BehaviorSubject([
      {
        paratextId: 'paratextId01',
        name: 'ParatextP1',
github intershop / intershop-pwa / src / app / core / store / shopping / shopping-store.spec.ts View on Github external
sortKeys: [],
        products: [{ sku: 'P1' }, { sku: 'P2' }] as Product[],
        total: 2,
      })
    );
    when(productsServiceMock.searchProducts('something', anyNumber(), anything())).thenReturn(
      of({ products: [{ sku: 'P2' } as Product], sortKeys: [], total: 1 })
    );

    promotionsServiceMock = mock(PromotionsService);
    when(promotionsServiceMock.getPromotion(anything())).thenReturn(of(promotion));

    suggestServiceMock = mock(SuggestService);
    when(suggestServiceMock.search('some')).thenReturn(of([{ term: 'something' }]));

    filterServiceMock = mock(FilterService);
    when(filterServiceMock.getFilterForSearch(anything())).thenReturn(of({} as FilterNavigation));
    when(filterServiceMock.getFilterForCategory(anything())).thenReturn(of({} as FilterNavigation));

    TestBed.configureTestingModule({
      declarations: [DummyComponent],
      imports: [
        RouterTestingModule.withRoutes([
          {
            path: 'home',
            component: DummyComponent,
          },
          {
            path: 'compare',
            component: DummyComponent,
          },
          {
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / app / checking / checking-overview / checking-overview.component.spec.ts View on Github external
});
});

@NgModule({
  imports: [FormsModule, MdcDialogModule, ReactiveFormsModule, NoopAnimationsModule, UICommonModule],
  exports: [QuestionDialogComponent],
  declarations: [QuestionDialogComponent],
  entryComponents: [QuestionDialogComponent]
})
class DialogTestModule {}

class TestEnvironment {
  component: CheckingOverviewComponent;
  fixture: ComponentFixture;

  mockedActivatedRoute: ActivatedRoute = mock(ActivatedRoute);
  mockedSFAdminAuthGuard: SFAdminAuthGuard = mock(SFAdminAuthGuard);
  mockedMdcDialog: MdcDialog = mock(MdcDialog);
  mockedQuestionDialogRef: MdcDialogRef = mock(MdcDialogRef);
  mockedNoticeService = mock(NoticeService);
  mockedProjectService: SFProjectService = mock(SFProjectService);
  mockedTextService: TextService = mock(TextService);
  mockedUserService: UserService = mock(UserService);
  mockedAuthService: AuthService = mock(AuthService);
  mockedRealtimeOfflineStore: RealtimeOfflineStore = mock(RealtimeOfflineStore);
  overlayContainer: OverlayContainer;

  constructor() {
    when(this.mockedActivatedRoute.params).thenReturn(of({}));
    when(this.mockedMdcDialog.open(anything(), anything())).thenReturn(instance(this.mockedQuestionDialogRef));
    when(this.mockedSFAdminAuthGuard.allowTransition(anything())).thenReturn(of(true));
    when(this.mockedProjectService.getTexts(anything())).thenReturn(
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / identity / log-in / log-in.component.spec.ts View on Github external
constructor() {
    this.mockedIdentityService = mock(IdentityService);
    this.mockedActivatedRoute = mock(ActivatedRoute);
    this.mockedLocationService = mock(LocationService);
    this.mockedAuthService = mock(AuthService);
    this.mockedNoticeService = mock(NoticeService);

    when(this.mockedActivatedRoute.queryParams).thenReturn(of({}));
    when(this.mockedNoticeService.show(anything())).thenResolve();

    TestBed.configureTestingModule({
      imports: [NoopAnimationsModule, UICommonModule],
      declarations: [LogInComponent],
      providers: [
        { provide: IdentityService, useFactory: () => instance(this.mockedIdentityService) },
        { provide: ActivatedRoute, useFactory: () => instance(this.mockedActivatedRoute) },
        { provide: LocationService, useFactory: () => instance(this.mockedLocationService) },
        { provide: AuthService, useFactory: () => instance(this.mockedAuthService) },
        { provide: NoticeService, useFactory: () => instance(this.mockedNoticeService) }
      ]
github articodeltd / angular-cesium / projects / angular-cesium / src / lib / angular-cesium / components / ac-ellipse / ac-ellipse.component.spec.ts View on Github external
describe('AcEllipseComponent', () => {
  let component: AcEllipseComponent;
  let fixture: ComponentFixture;

  const cesiumService = mock(CesiumService);
  const primitiveCollection = mock(Cesium.PrimitiveCollection);

  when(cesiumService.getScene()).thenReturn({primitives: instance(primitiveCollection)});

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AcEllipseComponent],
      providers: [EllipseDrawerService, MapLayersService,
        providerFromMock(CesiumService, cesiumService)]
    })
      .compileComponents();
    fixture = TestBed.createComponent(AcEllipseComponent);
    component = fixture.componentInstance;

  }));
github articodeltd / angular-cesium / projects / angular-cesium / src / lib / angular-cesium / components / ac-circle / ac-circle.component.spec.ts View on Github external
describe('AcCircleComponent', () => {
  let component: AcCircleComponent;
  let fixture: ComponentFixture;

  const cesiumService = mock(CesiumService);
  const primitiveCollection = mock(Cesium.PrimitiveCollection);

  when(cesiumService.getScene()).thenReturn({primitives: instance(primitiveCollection)});

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AcCircleComponent],
      providers: [EllipseDrawerService, MapLayersService,
        providerFromMock(CesiumService, cesiumService)]
    })
      .compileComponents();
    fixture = TestBed.createComponent(AcCircleComponent);
    component = fixture.componentInstance;

  }));
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / system-administration / sa-delete-dialog.component.spec.ts View on Github external
constructor() {
    this.mockedUserService = mock(UserService);

    TestBed.configureTestingModule({
      imports: [NoopAnimationsModule, UICommonModule],
      declarations: [SaDeleteDialogComponent],
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
      providers: [
        { provide: UserService, useFactory: () => instance(this.mockedUserService) },
        { provide: MAT_DIALOG_DATA },
        { provide: MatDialogRef, useValue: {} }
      ]
    });

    this.fixture = TestBed.createComponent(SaDeleteDialogComponent);
    this.component = this.fixture.componentInstance;
  }
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / identity / verify-email / verify-email.component.spec.ts View on Github external
constructor(isVerified = true) {
    this.mockedAuthService = mock(AuthService);
    this.mockedActivatedRoute = mock(ActivatedRoute);
    this.mockedIdentityService = mock(IdentityService);
    this.mockedNoticeService = mock(NoticeService);

    const params: Params = { ['key']: 'test_verification_key' };
    when(this.mockedAuthService.isLoggedIn).thenResolve(true);
    when(this.mockedActivatedRoute.queryParams).thenReturn(of(params));
    when(this.mockedIdentityService.verifyEmail(anything())).thenResolve(isVerified);
    when(this.mockedIdentityService.resendLink(anything())).thenResolve('success');

    TestBed.configureTestingModule({
      imports: [UICommonModule],
      declarations: [VerifyEmailComponent],
      providers: [
        { provide: AuthService, useFactory: () => instance(this.mockedAuthService) },
        { provide: ActivatedRoute, useFactory: () => instance(this.mockedActivatedRoute) },
        { provide: IdentityService, useFactory: () => instance(this.mockedIdentityService) },
github articodeltd / angular-cesium / src / components / ac-static-circle-desc / ac-static-circle-desc.component.spec.ts View on Github external
beforeEach(async(() => {
		const mockCesiumService = mock(CesiumService);
		const mockStaticCircleDrawerService = mock(StaticCircleDrawerService);
		const mockLayerService = mock(LayerService);
		const mockComputationCache = mock(ComputationCache);
		const mockCesiumProperties = mock(CesiumProperties);

		TestBed.configureTestingModule({
			declarations: [AcStaticCircleDescComponent],
			providers: [
				{
					provide: CesiumService,
					useValue: mockCesiumService
				},
				{
					provide: StaticCircleDrawerService,
					useValue: mockStaticCircleDrawerService
				},
				{
					provide: LayerService,
					useValue: mockLayerService