Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
directorRepository = mock(DirectorRepository);
serviceUnderTest = new DirectorService(
instance(directorRepository),
);
});
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) => {
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));
});
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;
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;
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;
}, {}));
});
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
]
});
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));
});
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));
});
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]
})