How to use the ts-mockito.anything 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 / 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 ivarvh / movielistr-backend-ts-ioc / test / controllers / MovieController.spec.ts View on Github external
const requestBody = {
                title: movieWithoutId.$title,
                releaseYear: movieWithoutId.$releaseYear,
                duration: movieWithoutId.$duration,
                rating: movieWithoutId.$rating,
                seen: movieWithoutId.$seen,
                director: {
                    id: movieWithoutId.$director.$id,
                    firstName: movieWithoutId.$director.$firstName,
                    lastName: movieWithoutId.$director.$lastName,
                    birthYear: movieWithoutId.$director.$birthYear,
                },
            };
            ctx.request.body = requestBody;

            when(movieService.save(anything()))
                .thenReturn(Promise.resolve(movieWithId));

            await controllerUnderTest.saveMovie(ctx);

            const [firstArg] = capture(movieService.save).last();
            console.log(JSON.stringify(firstArg));
            expect(firstArg.$id).equals(undefined);
            expect(firstArg.$title).equals(requestBody.title);
            expect(firstArg.$releaseYear).equals(requestBody.releaseYear);
            expect(firstArg.$duration).equals(requestBody.duration);
            expect(firstArg.$rating).equals(requestBody.rating);
            expect(firstArg.$seen).equals(requestBody.seen);
            expect(firstArg.$director.$id).equals(requestBody.director.id);
            expect(firstArg.$director.$firstName).equals(requestBody.director.firstName);
            expect(firstArg.$director.$lastName).equals(requestBody.director.lastName);
            expect(firstArg.$director.$birthYear).equals(requestBody.director.birthYear);
github articodeltd / angular-cesium / src / angular-cesium / services / drawers / arc-drawer / arc-drawer.service.spec.ts View on Github external
it('should create and return a new  arc primitive.', inject([ArcDrawerService], (service: ArcDrawerService) => {
		const arc = service.add(arcProps.geometryProps, arcProps.instanceProps, arcProps.primitiveProps);

		verify(primitiveCollection.add(anything())).once();
		expect(arc).toBeDefined();
	}));
github intershop / intershop-pwa / src / app / extensions / quoting / store / quote-request / quote-request.effects.spec.ts View on Github external
it('should call the quoteService for updateQuoteRequest and for submitQuoteRequest and send an SubmitQuoteRequestFail action on error', done => {
      when(quoteRequestServiceMock.submitQuoteRequest(anything())).thenReturn(
        throwError({ message: 'something went wrong' })
      );

      actions$ = of(new quoteRequestActions.UpdateSubmitQuoteRequest({ displayName: 'edited' }));
      effects.updateSubmitQuoteRequest$.subscribe(action => {
        verify(quoteRequestServiceMock.updateQuoteRequest('QRID', deepEqual({ displayName: 'edited' }))).once();
        verify(quoteRequestServiceMock.submitQuoteRequest('QRID')).once();
        expect(action).toMatchInlineSnapshot(`
          [Quote API] Submit Quote Request Fail:
            error: {"message":"something went wrong"}
        `);
        done();
      });
    });
  });
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / app / translate / editor / editor.component.spec.ts View on Github external
it('change chapters', fakeAsync(() => {
    const env = new TestEnvironment();
    env.setTranslateConfig({ selectedTextRef: 'text01', selectedChapter: 1, selectedSegment: 'verse_1_1' });
    env.waitForSuggestion();
    expect(env.component.chapter).toBe(1);
    expect(env.component.target.segmentRef).toBe('verse_1_1');
    verify(env.mockedRemoteTranslationEngine.translateInteractively(1, anything())).once();

    resetCalls(env.mockedRemoteTranslationEngine);
    env.component.chapter = 2;
    env.waitForSuggestion();
    const verseText = env.component.target.getSegmentText('verse_2_1');
    expect(verseText).toBe('target: chapter 2, verse 1.');
    expect(env.component.target.segmentRef).toEqual('');
    verify(env.mockedRemoteTranslationEngine.translateInteractively(1, anything())).never();

    resetCalls(env.mockedRemoteTranslationEngine);
    env.component.chapter = 1;
    env.waitForSuggestion();
    expect(env.component.target.segmentRef).toBe('verse_1_1');
    verify(env.mockedRemoteTranslationEngine.translateInteractively(1, anything())).once();

    env.dispose();
  }));
github intershop / intershop-pwa / src / app / core / services / categories / categories.service.spec.ts View on Github external
it('should return error when called with empty category', done => {
      categoriesService.getCategory('').subscribe(fail, err => {
        expect(err).toBeTruthy();
        done();
      });

      verify(apiServiceMock.get(anything(), anything())).never();
    });
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / app / checking / checking-overview / checking-overview.component.spec.ts View on Github external
it('should add a question if requested', fakeAsync(() => {
      const env = new TestEnvironment();
      when(env.mockedQuestionDialogRef.afterClosed()).thenReturn(
        of({
          scriptureStart: 'MAT 3:3',
          scriptureEnd: '',
          text: ''
        })
      );
      env.fixture.detectChanges();
      flush();
      verify(env.mockedTextService.getQuestionData(anything())).twice();

      resetCalls(env.mockedTextService);
      env.clickElement(env.addQuestionButton);
      verify(env.mockedMdcDialog.open(anything(), anything())).once();
      verify(env.mockedTextService.getQuestionData(anything())).once();
      expect().nothing();
    }));
  });
github intershop / intershop-pwa / src / app / shared / cms / containers / content-include / content-include.container.spec.ts View on Github external
beforeEach(async(() => {
    include = createContentPageletEntryPointView({
      id: 'test.include',
      definitionQualifiedName: 'test.include-Include',
      domain: 'domain',
      displayName: 'displayName',
      resourceSetId: 'resId',
      configurationParameters: {
        key: '1',
      },
    });

    cmsFacade = mock(CMSFacade);
    when(cmsFacade.contentInclude$(anything())).thenReturn(of(include));
    when(cmsFacade.contentIncludeSfeMetadata$(anything())).thenReturn(EMPTY);

    TestBed.configureTestingModule({
      declarations: [ContentIncludeContainerComponent, MockComponent(ContentPageletContainerComponent)],
      providers: [{ provide: CMSFacade, useValue: instance(cmsFacade) }],
    }).compileComponents();
  }));
github intershop / intershop-pwa / src / app / core / services / user / user.service.spec.ts View on Github external
userService.signinUserByToken('dummy').subscribe(data => {
        verify(apiServiceMock.get(anything(), anything())).once();
        const [path, options] = capture(apiServiceMock.get).last();
        expect(path).toEqual('customers/-');
        expect(options.headers.get(ApiService.TOKEN_HEADER_KEY)).toEqual('dummy');
        expect(data).toHaveProperty('user.email', 'test@intershop.de');
        done();
      });
    });
github intershop / intershop-pwa / src / app / core / store / user / user.effects.spec.ts View on Github external
beforeEach(() => {
    userServiceMock = mock(UserService);
    when(userServiceMock.signinUser(anything())).thenReturn(of(loginResponseData));
    when(userServiceMock.createUser(anything())).thenReturn(of(undefined));
    when(userServiceMock.updateUser(anything())).thenReturn(of({ firstName: 'Patricia' } as User));
    when(userServiceMock.updateUserPassword(anything(), anything(), anything(), anyString())).thenReturn(of(undefined));
    when(userServiceMock.updateCustomer(anything())).thenReturn(of(customer));
    when(userServiceMock.getCompanyUserData()).thenReturn(of({ firstName: 'Patricia' } as User));
    when(userServiceMock.requestPasswordReminder(anything())).thenReturn(of({}));

    TestBed.configureTestingModule({
      declarations: [DummyComponent],
      imports: [
        RouterTestingModule.withRoutes([
          { path: 'login', component: DummyComponent },
          { path: 'home', component: DummyComponent },
          { path: 'account', component: DummyComponent },
          { path: 'foobar', component: DummyComponent },
        ]),
        ngrxTesting({ reducers: coreReducers }),