I'm new to Angular I created a project with it which is working fine so far. But now I want to add some testing to it.
Unfortunately I'm not able to make it work.
So my app is a basic todo app.
In the test I want to check if task was created.
This is my task-form.po.ts
import { by, element, ElementArrayFinder, ElementFinder } from 'protractor';
export class TaskForm {
get taskCreateButton(): ElementFinder {
return element(by.css('#task-create-btn'));
}
get taskListItems(): ElementArrayFinder {
return element.all(by.css('mat-list-item'));
}
get taskForm(): ElementFinder {
return element(by.id('task-form'));
}
get taskFormInput(): ElementFinder {
return element(by.id('mat-input-0'));
}
}
app.e2e-spec.ts
...
describe('TaskForm', () => {
let taskForm: TaskForm;
let startCount: number;
let createBtn: ElementFinder;
let taskListItems: ElementArrayFinder;
let taskFormNewInput: ElementFinder;
let newTaskItemsNum: number;
beforeEach( () => {
taskForm = new TaskForm();
createBtn = taskForm.taskCreateButton;
taskListItems = taskForm.taskListItems;
taskFormNewInput = taskForm.taskFormInput;
taskListItems.count().then((originalCount: number) => {
startCount = originalCount;
});
});
it('should enter test task to task form', async () => {
await taskFormNewInput.clear().then(() => {
taskFormNewInput.sendKeys('This is a test task');
});
taskFormNewInput.getAttribute('value').then(taskInput => {
expect(taskInput).toEqual('This is a test task');
});
});
it('should add a task', async () => {
await taskFormNewInput.clear().then(() => {
taskFormNewInput.sendKeys('This is a test task');
});
await createBtn.click();
newTaskItemsNum = await taskForm.taskListItems.count();
expect(newTaskItemsNum).toBe(startCount);
});
});
The task will be added but then it's running in a script timeout.
I tried several things but either the task will not be created or it's running in a script timeout.
Aucun commentaire:
Enregistrer un commentaire