forked from cucumber/cucumber-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typescript: type this as IWorld in user functions (cucumber#1690)
* type this as any in user fns, add test * update changelog * setWorldConstructor for completeness * use generics to do it right * Update CHANGELOG.md * use a clearer generic type name
- Loading branch information
1 parent
9e89686
commit 8a0d5e8
Showing
7 changed files
with
159 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Before, setWorldConstructor, When, 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() | ||
}) |