How to use the ts-mockito/lib/ts-mockito.when 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 ivarvh / movielistr-backend-ts-ioc / test / services / DirectorService.spec.ts View on Github external
it("should add a director with the given information", async () => {
            when(directorRepository.saveDirector(testDirectorWithoutId)).thenReturn(Promise.resolve(testDirectorWithId));
            const actual = await serviceUnderTest.save(testDirectorWithoutId);
            expect(actual).to.equal(testDirectorWithId);
        });
github ivarvh / movielistr-backend-ts-ioc / test / services / DirectorService.spec.ts View on Github external
it("should return the 4 dummy directors", async () => {
            when(directorRepository.getAllDirectors()).thenReturn(Promise.resolve(testDirectorList));
            const actual = await serviceUnderTest.findAll();
            expect(actual).to.have.length(5);
        });
    });
github ivarvh / movielistr-backend-ts-ioc / test / services / DirectorService.spec.ts View on Github external
it("should call the delete on the repository", async () => {
            when(directorRepository.deleteDirectorWithId(testId)).thenReturn(Promise.resolve());
            await serviceUnderTest.delete(testId);
            verify(directorRepository.deleteDirectorWithId(testId)).called();
        });
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / system-administration / sa-user-entry.component.spec.ts View on Github external
constructor() {
    this.mockedUserService = mock(UserService);
    this.mockedNoticeService = mock(NoticeService);
    const updatedUser = new User({
      id: 'user01',
      name: 'Updated Name',
      username: 'updatedusername'
    });
    when(this.mockedUserService.onlineUpdateAttributes(anything(), anything())).thenResolve(updatedUser);
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule, NoopAnimationsModule, UICommonModule],
      declarations: [SaUserEntryComponent],
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
      providers: [
        { provide: UserService, useFactory: () => instance(this.mockedUserService) },
        { provide: NoticeService, useFactory: () => instance(this.mockedNoticeService) },
        DatePipe
      ]
    });

    this.fixture = TestBed.createComponent(SaUserEntryComponent);
    this.component = this.fixture.componentInstance;
  }