-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
world.ts
75 lines (69 loc) · 1.78 KB
/
world.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Before, setWorldConstructor, When, IWorld, World } from '../'
import { expectError } from 'tsd'
// should allow us to read parameters and add attachments
Before(async function () {
await this.attach(this.parameters.foo)
})
When('stuff happens', async function () {
await this.attach(this.parameters.foo)
})
// should prevent reassignment of parameters
expectError(
Before(async function () {
this.parameters = null
})
)
expectError(
When('stuff happens', async function () {
this.parameters = null
})
)
// should allow us to set and get arbitrary properties
Before(async function () {
this.bar = 'baz'
await this.log(this.baz)
})
When('stuff happens', async function () {
this.bar = 'baz'
await this.log(this.baz)
})
// should allow us to use a custom world class
class CustomWorld extends World {
doThing(): string {
return 'foo'
}
}
setWorldConstructor(CustomWorld)
Before(async function (this: CustomWorld) {
this.doThing()
})
When('stuff happens', async function (this: CustomWorld) {
this.doThing()
})
// should allow us to use a custom parameters type without a custom world
interface CustomParameters {
foo: string
}
Before(async function (this: IWorld<CustomParameters>) {
this.log(this.parameters.foo)
})
expectError(
Before(async function (this: IWorld<CustomParameters>) {
this.log(this.parameters.bar)
})
)
// should allow us to use a custom parameters type with a custom world
class CustomWorldWithParameters extends World<CustomParameters> {
doThing(): string {
return 'foo'
}
}
setWorldConstructor(CustomWorldWithParameters)
Before(async function (this: CustomWorldWithParameters) {
this.log(this.parameters.foo)
})
expectError(
Before(async function (this: CustomWorldWithParameters) {
this.log(this.parameters.bar)
})
)