Skip to content

Instantly share code, notes, and snippets.

View advorkina's full-sized avatar

Anastasia Dvorkina advorkina

View GitHub Profile
@advorkina
advorkina / folder-name.component.spec.ts
Last active May 7, 2018 21:29
Testing Input() properties in Angular
it("should set input property 'text' equal to folder title in <custom-inline-edit/>", () => {
// arrange
component.folder = folder;
fixture.detectChanges();
// act
let inlineEditElement: DebugElement = editDescriptionElement = fixture.debugElement.query(
By.css("custom-inline-edit"));
// assert
@advorkina
advorkina / folder-name.component.spec.ts
Last active December 4, 2019 17:24
Testing Output() event
it("should emit folder with the new title on editTitleConfiremd", () => {
// arrange
component.folder.title = "Harry Potter";
fixture.detectChanges();
spyOn(component.folderUpdated, "emit");
// act
let inlineEditElement: DebugElement = editDescriptionElement = fixture.debugElement.query(
By.css("custom-inline-edit"));
inlineEditElement.triggerEventHandler("editConfirmed", "Albus Dumbledore");
@advorkina
advorkina / folder-name.component.html
Last active May 7, 2018 21:12
html for testing inputs and outputs
<span *ngIf="folder" class="folder-name">
<custom-inline-edit [text]="folderTitle"
(editConfirmed)="editTitleConfirmed($event)"
(canceled)="editFolderCanceled.emit($event)">
</custom-inline-edit>
</span>
public editTitleConfirmed(title: string): void {
if (!title) {
return;
}
this.folderUpdated.emit({ ...this.folder, title: title });
}
it("should emit folder with the new title on Enter key", fakeAsync(() => {
// arrange
spyOn(component.folderUpdated, "emit");
// act
let inlineEditInputDebugElement: DebugElement = fixture.debugElement.query(
By.css("custom-inline-edit #title-input"));
let inlineEditInputElement: any = editDescriptionElement.nativeElement;
inlineEditInputElement.value = "Albus Dumbledore";
public selectFolder(folder: IFolder): void {
this.selectedFolder = folder;
}
describe("selectFolder", () => {
it("should update selectedFolder property with passed folder", () => {
// arrange
component.selectedFolder = undefined;
let folder: IFolder = new Folder(1, "Harry Potter");
// act
component.selectFolder(folder);
// assert
beforeEach(
async(() => {
TestBed.configureTestingModule({
providers: [SomeProvider],
declarations: [DropzoneComponent, DocumentsComponent, FoldersComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
})
);
<span [class.isActive]="isActive()">{{title}}</span>
<folders [folders]="folders"
[activeFolder]="activeFolder"
(folderSelected)="folderSelected($event)">
</folders>
<documents [documents]="documents"
(documentOpened)="documentOpened($event)">
</documents>
beforeEach(
async(() => {
TestBed.configureTestingModule({
providers: [SomeProvider],
declarations: [DropzoneComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
})
);