|
| 1 | +import { expectType } from "tsd"; |
| 2 | + |
| 3 | +import messages from "@cucumber/messages"; |
| 4 | + |
| 5 | +import "./"; |
| 6 | + |
| 7 | +import { |
| 8 | + Given, |
| 9 | + When, |
| 10 | + Then, |
| 11 | + Step, |
| 12 | + defineParameterType, |
| 13 | + Before, |
| 14 | + After, |
| 15 | + DataTable, |
| 16 | +} from "../methods"; |
| 17 | + |
| 18 | +Given("foo", function (foo, bar: number, baz: string) { |
| 19 | + expectType<Mocha.Context>(this); |
| 20 | + expectType<unknown>(foo); |
| 21 | + expectType<number>(bar); |
| 22 | + expectType<string>(baz); |
| 23 | +}); |
| 24 | + |
| 25 | +Given(/foo/, function (foo, bar: number, baz: string) { |
| 26 | + expectType<Mocha.Context>(this); |
| 27 | + expectType<unknown>(foo); |
| 28 | + expectType<number>(bar); |
| 29 | + expectType<string>(baz); |
| 30 | +}); |
| 31 | + |
| 32 | +When("foo", function (foo, bar: number, baz: string) { |
| 33 | + expectType<Mocha.Context>(this); |
| 34 | + expectType<unknown>(foo); |
| 35 | + expectType<number>(bar); |
| 36 | + expectType<string>(baz); |
| 37 | +}); |
| 38 | + |
| 39 | +When(/foo/, function (foo, bar: number, baz: string) { |
| 40 | + expectType<Mocha.Context>(this); |
| 41 | + expectType<unknown>(foo); |
| 42 | + expectType<number>(bar); |
| 43 | + expectType<string>(baz); |
| 44 | +}); |
| 45 | + |
| 46 | +Then("foo", function (foo, bar: number, baz: string) { |
| 47 | + expectType<Mocha.Context>(this); |
| 48 | + expectType<unknown>(foo); |
| 49 | + expectType<number>(bar); |
| 50 | + expectType<string>(baz); |
| 51 | +}); |
| 52 | + |
| 53 | +Then(/foo/, function (foo, bar: number, baz: string) { |
| 54 | + expectType<Mocha.Context>(this); |
| 55 | + expectType<unknown>(foo); |
| 56 | + expectType<number>(bar); |
| 57 | + expectType<string>(baz); |
| 58 | +}); |
| 59 | + |
| 60 | +declare const table: DataTable; |
| 61 | + |
| 62 | +Then("foo", function () { |
| 63 | + // Step should consume Mocha.Context. |
| 64 | + Step(this, "foo"); |
| 65 | +}); |
| 66 | + |
| 67 | +Then("foo", function () { |
| 68 | + // Step should consume DataTable's. |
| 69 | + Step(this, "foo", table); |
| 70 | +}); |
| 71 | + |
| 72 | +Then("foo", function () { |
| 73 | + // Step should consume doc strings. |
| 74 | + Step(this, "foo", "bar"); |
| 75 | +}); |
| 76 | + |
| 77 | +defineParameterType({ |
| 78 | + name: "foo", |
| 79 | + regexp: /foo/, |
| 80 | + transformer(foo, bar, baz) { |
| 81 | + expectType<Mocha.Context>(this); |
| 82 | + expectType<string>(foo); |
| 83 | + expectType<string>(bar); |
| 84 | + expectType<string>(baz); |
| 85 | + }, |
| 86 | +}); |
| 87 | + |
| 88 | +Before(function () { |
| 89 | + expectType<Mocha.Context>(this); |
| 90 | +}); |
| 91 | + |
| 92 | +Before({}, function () { |
| 93 | + expectType<Mocha.Context>(this); |
| 94 | +}); |
| 95 | + |
| 96 | +Before({ tags: "foo" }, function () { |
| 97 | + expectType<Mocha.Context>(this); |
| 98 | +}); |
| 99 | + |
| 100 | +After(function () { |
| 101 | + expectType<Mocha.Context>(this); |
| 102 | +}); |
| 103 | + |
| 104 | +After({}, function () { |
| 105 | + expectType<Mocha.Context>(this); |
| 106 | +}); |
| 107 | + |
| 108 | +After({ tags: "foo" }, function () { |
| 109 | + expectType<Mocha.Context>(this); |
| 110 | +}); |
| 111 | + |
| 112 | +expectType<messages.GherkinDocument>(window.testState.gherkinDocument); |
| 113 | +expectType<messages.Pickle[]>(window.testState.pickles); |
| 114 | +expectType<messages.Pickle>(window.testState.pickle); |
0 commit comments