How to use the ts-mockito.capture 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 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 intershop / intershop-pwa / src / app / extensions / quoting / shared / product / components / product-add-to-quote-dialog / product-add-to-quote-dialog.component.spec.ts View on Github external
it('should throw updateSubmitQuoteRequest event when submit is clicked and the form values were changed before ', () => {
      const emitter = spy(component.updateSubmitQuoteRequest);

      component.form.value.displayName = 'DNAME';
      component.form.value.description = 'DESC';
      component.form.markAsDirty();

      component.submit();
      verify(emitter.emit(anything())).once();
      const [arg] = capture(emitter.emit).last();
      expect(arg).toMatchInlineSnapshot(`
        Object {
          "description": "DESC",
          "displayName": "DNAME",
        }
      `);
    });
  });
github GNS3 / gns3-web-ui / src / app / components / project-map / project-map-shortcuts / project-map-shortcuts.component.spec.ts View on Github external
it('should remove binding', () => {
    component.ngOnDestroy();
    const [hotkey] = capture(hotkeyServiceMock.remove).last();
    expect((hotkey as Hotkey).combo).toEqual(['del']);
  });
github intershop / intershop-pwa / src / app / core / utils / dev / api-service-utils.ts View on Github external
export function logApiCalls(apiServiceMock: ApiService) {
  for (let i = 0; i < 100; i++) {
    try {
      const args = capture(apiServiceMock.get).byCallIndex(i);
      console.log('GET', args);
    } catch (err) {
      break;
    }
  }
  for (let i = 0; i < 100; i++) {
    try {
      const args = capture(apiServiceMock.post).byCallIndex(i);
      console.log('POST', args);
    } catch (err) {
      break;
    }
  }
  for (let i = 0; i < 100; i++) {
    try {
      const args = capture(apiServiceMock.put).byCallIndex(i);
      console.log('PUT', args);
    } catch (err) {
      break;
    }
  }
}
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / change-password / change-password.component.spec.ts View on Github external
it('clicking submit calls library, shows notice, goes /projects', fakeAsync(() => {
    const newPassword = 'aaaaaaa';
    env.newPasswordControl.setValue(newPassword);
    env.confirmPasswordControl.setValue(newPassword);
    env.fixture.detectChanges();
    env.clickSubmit();
    verify(env.mockedUserService.onlineChangePassword(anyString())).once();
    const arg = capture(env.mockedUserService.onlineChangePassword).last()[0];
    expect(arg).toEqual(newPassword);
    verify(env.mockedNoticeService.show(anyString())).once();
    verify(env.mockedRouter.navigateByUrl(anyString())).once();
    const routerArg = capture(env.mockedRouter.navigateByUrl).last()[0];
    expect(routerArg).toEqual('/projects');
  }));
github intershop / intershop-pwa / src / app / core / utils / dev / api-service-utils.ts View on Github external
console.log('GET', args);
    } catch (err) {
      break;
    }
  }
  for (let i = 0; i < 100; i++) {
    try {
      const args = capture(apiServiceMock.post).byCallIndex(i);
      console.log('POST', args);
    } catch (err) {
      break;
    }
  }
  for (let i = 0; i < 100; i++) {
    try {
      const args = capture(apiServiceMock.put).byCallIndex(i);
      console.log('PUT', args);
    } catch (err) {
      break;
    }
  }
}
github intershop / intershop-pwa / src / app / core / store / checkout / basket / basket-items.effects.spec.ts View on Github external
effects.updateBasketItems$.subscribe(() => {
        verify(basketServiceMock.updateBasketItem('BID', payload.lineItemUpdates[1].itemId, anything())).thrice();
        expect(capture(basketServiceMock.updateBasketItem).first()).toMatchInlineSnapshot(`
          Array [
            "BID",
            "BIID",
            Object {
              "product": undefined,
              "quantity": Object {
                "unit": undefined,
                "value": 2,
              },
            },
          ]
        `);
        expect(capture(basketServiceMock.updateBasketItem).second()).toMatchInlineSnapshot(`
          Array [
            "BID",
            "BIID",
github intershop / intershop-pwa / src / app / core / services / order / order.service.spec.ts View on Github external
orderService.getOrderByToken('id12345', 'dummy').subscribe(data => {
      verify(apiService.get(anything(), anything())).once();
      const [path, options] = capture(apiService.get).last();
      expect(path).toEqual('orders/id12345');
      expect(options.headers.get(ApiService.TOKEN_HEADER_KEY)).toEqual('dummy');
      expect(data).toHaveProperty('id', 'id12345');
      done();
    });
  });
github intershop / intershop-pwa / src / app / core / store / locale / locale.effects.spec.ts View on Github external
effects.setLocale$.subscribe(() => {
        verify(translateServiceMock.use(anything())).once();
        const params = capture(translateServiceMock.use).last();
        expect(params[0]).toEqual('en_US');
        done();
      });