-
Notifications
You must be signed in to change notification settings - Fork 4
/
commands.ts
52 lines (45 loc) · 1.21 KB
/
commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {Actor, Question, Task} from "./index";
let _actor = new Actor();
declare namespace Cypress {
interface Chainable<Subject> {
/**
* Initiate with a different actor.
*
* Allows to set a customized actor with specialised abilities.
*
* @param actor
*/
initiateActor(actor: Actor) : Chainable<void>;
/**
* Perform a given task.
*
* @param task
* The task implementation.
* @param param
* The tasks parameter.
*/
perform<P>(task: Task<P>, param: P) : Chainable<void>;
/**
* Ask a question.
*
* The questions result will be returned as a chainable.
*
* @param question
* The question implementation.
* @param param
* Question parameter.
*/
ask<P,R>(question: Question<P,R>, param: P) : Chainable<R>;
}
}
Cypress.Commands.add('initiateActor', (actor: Actor) => {
_actor = actor;
});
Cypress.Commands.add('perform', (task: Task<any>, param: any = undefined) => {
_actor.perform(task, param);
});
Cypress.Commands.add('ask', (question: Question<any, any>, param: any = undefined) => {
return cy.wrap(new Cypress.Promise(resolve => {
_actor.ask(question, param, resolve);
}));
});