Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useExistingUser(): void {
when(this.mockedUserService.onlineGet(anything())).thenReturn(of(new MapQueryResults(this.testUser)));
// set the editUserId to display the details of the test user
this.component.editUserId = 'user01';
this.fixture.detectChanges();
tick();
}
it('should return data returened by http', () => {
const suggestionData = new ArrayBuffer(3);
when(httpClient.get(anything(), anything())).thenReturn(Observable.of(suggestionData));
let suggestionResults;
mockApiService.get('suggest?SearchTerm=', null, null).subscribe((data) => {
suggestionResults = suggestionData;
});
expect(suggestionResults).toBe(suggestionData);
});
});
it('should not submit if form is invalid ', fakeAsync(() => {
const env = new TestUserEntryComponent();
env.simulateAddUser();
env.setInputValue(env.nameInput, '');
expect(env.component.fullName.hasError('required')).toBe(true);
env.setInputValue(env.emailInput, 'invalidemail');
expect(env.component.email.hasError('email')).toBe(true);
env.setInputValue(env.emailInput, 'invalidemail@example');
expect(env.component.email.hasError('pattern')).toBe(true);
env.setInputValue(env.passwordInput, '');
expect(env.component.password.hasError('required')).toBe(true);
env.clickElement(env.addButton);
verify(env.mockedUserService.onlineCreate(anything())).never();
verify(env.mockedNoticeService.show(anything())).never();
}));
}).compileComponents().then(() => {
fixture = TestBed.createComponent(SubCategoryNavigationComponent);
component = fixture.componentInstance;
category.hasOnlineSubCategories = true;
category.subCategories = categories;
component.category = category;
component.currentCategoryUri = 'Computers/06';
component.category.uri = '/categories/Computers/06';
when(categoriesServiceMock.getCategory(anything())).thenReturn(Observable.of(category));
});
}));
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('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;
}, {}));
});
when(translateServiceMock.get(anyString())).thenCall((input: string) => {
return Observable.of(translateServiceMock.content[input] ? translateServiceMock.content[input] + 'en' : input);