How to use ts-mockito - 10 common examples

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 mongodb / stitch-js-sdk / packages / core / sdk / __tests__ / internal / net / StitchRequestClientUnitTests.ts View on Github external
.then(response => {
        expect(response.statusCode).toBe(200);
        const expected = {
          a: 42,
          hello: "world"
        };
        expect(expected).toEqual(EJSON.parse(response.body!, { relaxed: true }));

        // Error responses should be handled
        when(transportMock.roundTrip(anything())).thenResolve({
          headers: {},
          statusCode: 500
        });

        return stitchRequestClient.doRequest(builder.build());
      })
      .catch((error: StitchServiceError) => {
github mongodb / stitch-js-sdk / packages / core / services / mongodb-remote / __tests__ / CoreRemoteMongoCollectionUnitTests.ts View on Github external
serviceMock.callFunction(anything(), anything(), anything())
    ).times(2);

    const [funcNameArg2, funcArgsArg2, resultClassArg2]: any[] = capture(
      serviceMock.callFunction
    ).last();

    expect("updateOne").toEqual(funcNameArg2);
    expect(1).toEqual(funcArgsArg2.length);
    expectedArgs.upsert = true;
    expect(expectedArgs).toEqual(funcArgsArg2[0]);
    expect(ResultDecoders.remoteUpdateResultDecoder).toEqual(resultClassArg2);

    // Should pass along errors
    when(
      serviceMock.callFunction(anything(), anything(), anything())
    ).thenReject(new Error("whoops"));
    try {
      await coll.updateOne({}, {});
      fail();
    } catch (_) {
      // Do nothing
    }
  });
github mongodb / stitch-js-sdk / packages / core / sdk / __tests__ / auth / providers / userpassword / internal / CoreUserPasswordAuthProviderClientUnitTests.ts View on Github external
.then(() => {
        verify(requestClientMock.doRequest(anything())).times(1);

        const [requestArg] = capture(requestClientMock.doRequest).last();

        expect(expectedRequest).toEqualRequest(requestArg);

        // Should pass along errors
        when(requestClientMock.doRequest(anything())).thenThrow(
          new Error("whoops")
        );

        return expect(fun(client));
      })
      .catch(err => {
github mongodb / stitch-js-sdk / packages / core / sdk / __tests__ / auth / providers / userapikey / CoreUserApiKeyAuthProviderClientUnitTests.ts View on Github external
.then(() => {
      verify(requestClientMock.doAuthenticatedRequest(anything())).times(1);

      const [requestArg] = capture(
        requestClientMock.doAuthenticatedRequest
      ).last();

      expect(expectedRequest).toEqualRequest(requestArg);

      // Should pass along errors
      when(requestClientMock.doAuthenticatedRequest(anything())).thenThrow(
        new Error("whoops")
      );

      return fun(client);
    })
    .catch((err: Error) => {
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / identity / sign-up / sign-up.component.spec.ts View on Github external
it('should log out any user', fakeAsync(() => {
    const env = new TestEnvironment();
    env.fixture.detectChanges();
    // ensure that ngOnInit completes, then detect changes again
    flush();
    env.fixture.detectChanges();
    verify(env.mockedAuthService.logOutNoRedirect()).once();
    expect().nothing();
  }));
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / system-administration / sa-user-entry.component.spec.ts View on Github external
it('should allow the user to be updated when password field is untouched', fakeAsync(() => {
      const env = new TestUserEntryComponent();
      env.useExistingUser();
      expect(env.component.showPasswordPanel).toBe(false);
      // The user's password is not stored on the form
      expect(env.component.password.value).toBe('');
      expect(env.component.password.hasError('required')).toBe(true);
      // The validations on the password get bypassed when showPasswordPanel is false
      env.clickElement(env.updateButton);
      verify(env.mockedUserService.onlineUpdateAttributes(anything(), anything())).once();
    }));
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / system-administration / sa-user-entry.component.spec.ts View on Github external
useExistingUser(): void {
    when(this.mockedUserService.onlineGet(anything())).thenReturn(of(new MapQueryResults(this.testUser)));
    // set the editUserId to display the details of the test user
    this.component.editUserId = 'user01';
    this.fixture.detectChanges();
    tick();
  }
github intershop / intershop-pwa / src / app / services / routes-parser-locale-currency / localize-router.parser.spec.ts View on Github external
let routes: Routes;
  let locales: any;
  let langs: string[];
  const prefix = 'PREFIX.';
  const translateServiceMock: any = mock(TranslateService);
  const locationMock: any = mock(Location);
  when(locationMock.path(anything())).thenReturn('');
  translateServiceMock.content = {
    'PREFIX.home': 'home_',
    'PREFIX.about': 'about_',
    'PREFIX.contact': 'contact_',
    'PREFIX.info': 'info_'
  };
  when(translateServiceMock.setDefaultLang(anyString())).thenReturn();
  when(translateServiceMock.getDefaultLang()).thenReturn('En');
  when(translateServiceMock.use(anyString())).thenCall((lang: string) => {
    return Observable.of(Object.keys(translateServiceMock.content).reduce((prev: any, key) => {
      prev[key] = translateServiceMock.content[key] + lang;
      return prev;
    }, {}));
  });
  when(translateServiceMock.get(anyString())).thenCall((input: string) => {
    return Observable.of(translateServiceMock.content[input] ? translateServiceMock.content[input] + 'en' : input);
  });
  when(translateServiceMock.getBrowserLang()).thenReturn('En');

  // tslint:disable-next-line:prefer-mocks-instead-of-stubs-in-tests
  class ManualParserLoader extends LocalizeParser {
    constructor(translateService: TranslateService,
      locationService: Location,
      localizeRouterSettings: LocalizeRouterSettings,
      languages: string[],
github intershop / intershop-pwa / src / app / services / routes-parser-locale-currency / localize-router.parser.spec.ts View on Github external
when(locationMock.path(anything())).thenReturn('');
  translateServiceMock.content = {
    'PREFIX.home': 'home_',
    'PREFIX.about': 'about_',
    'PREFIX.contact': 'contact_',
    'PREFIX.info': 'info_'
  };
  when(translateServiceMock.setDefaultLang(anyString())).thenReturn();
  when(translateServiceMock.getDefaultLang()).thenReturn('En');
  when(translateServiceMock.use(anyString())).thenCall((lang: string) => {
    return Observable.of(Object.keys(translateServiceMock.content).reduce((prev: any, key) => {
      prev[key] = translateServiceMock.content[key] + lang;
      return prev;
    }, {}));
  });
  when(translateServiceMock.get(anyString())).thenCall((input: string) => {
    return Observable.of(translateServiceMock.content[input] ? translateServiceMock.content[input] + 'en' : input);
  });
  when(translateServiceMock.getBrowserLang()).thenReturn('En');

  // tslint:disable-next-line:prefer-mocks-instead-of-stubs-in-tests
  class ManualParserLoader extends LocalizeParser {
    constructor(translateService: TranslateService,
      locationService: Location,
      localizeRouterSettings: LocalizeRouterSettings,
      languages: string[],
      localesCollection: any,
      prefixes: string = 'ROUTES.',
      pattern: string = '{LANG}/{CURRENCY}') {
      super(translateService, locationService, localizeRouterSettings);
      this.langs = languages;
      this.localesCollection = localesCollection;
github intershop / intershop-pwa / src / app / services / routes-parser-locale-currency / localize-router.parser.spec.ts View on Github external
let settings: LocalizeRouterSettings;

  let routes: Routes;
  let locales: any;
  let langs: string[];
  const prefix = 'PREFIX.';
  const translateServiceMock: any = mock(TranslateService);
  const locationMock: any = mock(Location);
  when(locationMock.path(anything())).thenReturn('');
  translateServiceMock.content = {
    'PREFIX.home': 'home_',
    'PREFIX.about': 'about_',
    'PREFIX.contact': 'contact_',
    'PREFIX.info': 'info_'
  };
  when(translateServiceMock.setDefaultLang(anyString())).thenReturn();
  when(translateServiceMock.getDefaultLang()).thenReturn('En');
  when(translateServiceMock.use(anyString())).thenCall((lang: string) => {
    return Observable.of(Object.keys(translateServiceMock.content).reduce((prev: any, key) => {
      prev[key] = translateServiceMock.content[key] + lang;
      return prev;
    }, {}));
  });
  when(translateServiceMock.get(anyString())).thenCall((input: string) => {
    return Observable.of(translateServiceMock.content[input] ? translateServiceMock.content[input] + 'en' : input);
  });
  when(translateServiceMock.getBrowserLang()).thenReturn('En');

  // tslint:disable-next-line:prefer-mocks-instead-of-stubs-in-tests
  class ManualParserLoader extends LocalizeParser {
    constructor(translateService: TranslateService,
      locationService: Location,