How to use the ts-mockito/lib/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 ivarvh / movielistr-backend-ts-ioc / test / services / DirectorService.spec.ts View on Github external
beforeEach(() => {
        directorRepository = mock(DirectorRepository);
        serviceUnderTest = new DirectorService(
            instance(directorRepository),
        );
    });
github intershop / intershop-pwa / src / app / shared / services / suggest / search-box.service.api.spec.ts View on Github external
describe('Search Box Api Service', () => {
  const apiServiceMock: ApiService = mock(ApiService);

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        SearchBoxApiService,
        { provide: ApiService, useFactory: () => instance(apiServiceMock) },
      ],
    });
  });

  it('should search when search term is passed', inject([SearchBoxApiService], (searchBoxApiService: SearchBoxApiService) => {
    const searchTerm = searchBoxApiService.search(Observable.of('g'));
    expect(searchTerm).toBeTruthy();
  }));

  it('should call api service on receiving search term', inject([SearchBoxApiService], (searchBoxApiService: SearchBoxApiService) => {
github intershop / intershop-pwa / src / app / services / mock-api-service.spec.ts View on Github external
beforeEach(() => {
        httpClient = mock(HttpClient);
        customErrorHandler = mock(CustomErrorHandler);
        cacheCustomService = mock(CacheCustomService);
        const configSettings = {
            exlcudePath: ['categories12'],
            includePath: ['categories/computers12'],
            mockAllRequest: true
        };

        when(cacheCustomService.cacheKeyExists(anything())).thenReturn(true);
        when(cacheCustomService.getCachedData(anything())).thenReturn(configSettings);

        mockApiService = new MockApiService(instance(httpClient), instance(customErrorHandler), instance(cacheCustomService));
    });
github intershop / intershop-pwa / src / app / components / category-navigation / subcategory-navigation / subcategory-navigation.component.spec.ts View on Github external
beforeEach(async(() => {
    categoriesServiceMock = mock(CategoriesService);
    localizeServiceMock = mock(LocalizeRouterService);
    category.uri = '/categories/Cameras-Camcorders/585';

    TestBed.configureTestingModule({
      declarations: [SubCategoryNavigationComponent],
      imports: [RouterTestingModule],
      providers: [
        { provide: CategoriesService, useFactory: () => instance(categoriesServiceMock) },
        { provide: LocalizeRouterService, useFactory: () => instance(localizeServiceMock) }
      ],
      schemas: [NO_ERRORS_SCHEMA]
    }).compileComponents().then(() => {
      fixture = TestBed.createComponent(SubCategoryNavigationComponent);
      component = fixture.componentInstance;
      category.hasOnlineSubCategories = true;
      category.subCategories = categories;
github intershop / intershop-pwa / src / app / components / category-navigation / subcategory-navigation / subcategory-navigation.component.spec.ts View on Github external
beforeEach(async(() => {
    categoriesServiceMock = mock(CategoriesService);
    localizeServiceMock = mock(LocalizeRouterService);
    category.uri = '/categories/Cameras-Camcorders/585';

    TestBed.configureTestingModule({
      declarations: [SubCategoryNavigationComponent],
      imports: [RouterTestingModule],
      providers: [
        { provide: CategoriesService, useFactory: () => instance(categoriesServiceMock) },
        { provide: LocalizeRouterService, useFactory: () => instance(localizeServiceMock) }
      ],
      schemas: [NO_ERRORS_SCHEMA]
    }).compileComponents().then(() => {
      fixture = TestBed.createComponent(SubCategoryNavigationComponent);
      component = fixture.componentInstance;
      category.hasOnlineSubCategories = true;
      category.subCategories = categories;
      component.category = category;
github intershop / intershop-pwa / src / app / services / routes-parser-locale-currency / localize-router.parser.spec.ts View on Github external
describe('LocalizeParser', () => {
  let injector: Injector;
  let loader: ManualParserLoader;
  let translate: TranslateService;
  let location: Location;
  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;
    }, {}));
  });
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
      ]
    });
github intershop / intershop-pwa / src / app / services / mock-api-service.spec.ts View on Github external
beforeEach(() => {
        httpClient = mock(HttpClient);
        customErrorHandler = mock(CustomErrorHandler);
        cacheCustomService = mock(CacheCustomService);
        const configSettings = {
            exlcudePath: ['categories12'],
            includePath: ['categories/computers12'],
            mockAllRequest: true
        };

        when(cacheCustomService.cacheKeyExists(anything())).thenReturn(true);
        when(cacheCustomService.getCachedData(anything())).thenReturn(configSettings);

        mockApiService = new MockApiService(instance(httpClient), instance(customErrorHandler), instance(cacheCustomService));
    });
github intershop / intershop-pwa / src / app / services / mock-api-service.spec.ts View on Github external
beforeEach(() => {
        httpClient = mock(HttpClient);
        customErrorHandler = mock(CustomErrorHandler);
        cacheCustomService = mock(CacheCustomService);
        const configSettings = {
            exlcudePath: ['categories12'],
            includePath: ['categories/computers12'],
            mockAllRequest: true
        };

        when(cacheCustomService.cacheKeyExists(anything())).thenReturn(true);
        when(cacheCustomService.getCachedData(anything())).thenReturn(configSettings);

        mockApiService = new MockApiService(instance(httpClient), instance(customErrorHandler), instance(cacheCustomService));
    });
github intershop / intershop-pwa / src / app / components / category-family-host / category-family-host.component.spec.ts View on Github external
describe('Category Family Host Component', () => {
  let fixture: ComponentFixture;
  let component: CategoryFamilyHostComponent;
  const categoriesServiceMock: CategoriesService = mock(CategoriesService);
  class ActivtedRouteStub {
    params = Observable.of('url');
  }

  beforeEach(async(() => {

    TestBed.configureTestingModule({
      declarations: [
        CategoryFamilyHostComponent
      ],
      providers: [
        { provide: CategoriesService, useFactory: () => instance(categoriesServiceMock) },
        { provide: ActivatedRoute, useClass: ActivtedRouteStub }
      ],
      schemas: [NO_ERRORS_SCHEMA]
    })