Skip to content

Commit 83637a3

Browse files
committed
fix tests
1 parent 1655679 commit 83637a3

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

test/unit/functions/validation/functionPermutations.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,18 @@ const noSelfInFileTestFunctions: TestFunction[] = [
351351
},
352352
];
353353

354-
export const anonTestFunctionExpressions: TestFunction[] = [
355-
{ value: "s => s" },
356-
{ value: "(s => s)" },
354+
export const anonArrowFunctionExpressions: TestFunction[] = [{ value: "s => s" }, { value: "(s => s)" }];
355+
356+
export const anonNonArrowFunctionExpressions: TestFunction[] = [
357357
{ value: "function(s) { return s; }" },
358358
{ value: "(function(s) { return s; })" },
359359
];
360360

361+
export const anonTestFunctionExpressions: TestFunction[] = [
362+
...anonArrowFunctionExpressions,
363+
...anonNonArrowFunctionExpressions,
364+
];
365+
361366
export const selfTestFunctionExpressions: TestFunction[] = [
362367
{ value: "function(this: any, s) { return s; }" },
363368
{ value: "(function(this: any, s) { return s; })" },

test/unit/functions/validation/validFunctionAssignments.spec.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as util from "../../../util";
22
import {
3-
anonTestFunctionExpressions,
3+
anonArrowFunctionExpressions,
4+
anonNonArrowFunctionExpressions,
45
anonTestFunctionType,
56
noSelfTestFunctionExpressions,
67
noSelfTestFunctions,
@@ -133,10 +134,10 @@ test.each([
133134
});
134135

135136
test.each([
136-
...anonTestFunctionExpressions.map((f): [TestFunction, string[]] => [f, ["0", "'foobar'"]]),
137-
...selfTestFunctionExpressions.map((f): [TestFunction, string[]] => [f, ["0", "'foobar'"]]),
137+
...anonNonArrowFunctionExpressions.map((f): [TestFunction, string[]] => [f, ["'context'", "'foobar'"]]),
138+
...selfTestFunctionExpressions.map((f): [TestFunction, string[]] => [f, ["'context'", "'foobar'"]]),
138139
...noSelfTestFunctionExpressions.map((f): [TestFunction, string[]] => [f, ["'foobar'"]]),
139-
])("Valid function expression argument with no signature (%p, %p)", (testFunction, args) => {
140+
])("Valid function expression argument with no signature have context (%p, %p)", (testFunction, args) => {
140141
util.testFunction`
141142
const takesFunction: any = (fn: (this: void, ...args: any[]) => any, ...args: any[]) => {
142143
return fn(...args);
@@ -147,6 +148,20 @@ test.each([
147148
.expectToEqual("foobar");
148149
});
149150

151+
test.each([...anonArrowFunctionExpressions.map((f): [TestFunction, string[]] => [f, ["'foobar'"]])])(
152+
"Valid arrow function expression argument with no signature do not have context (%p, %p)",
153+
(testFunction, args) => {
154+
util.testFunction`
155+
const takesFunction: any = (fn: (this: void, ...args: any[]) => any, ...args: any[]) => {
156+
return fn(...args);
157+
}
158+
return takesFunction(${testFunction.value}, ${args.join(", ")});
159+
`
160+
.setTsHeader(testFunction.definition ?? "")
161+
.expectToEqual("foobar");
162+
}
163+
);
164+
150165
test.each(validTestFunctionAssignments)("Valid function return (%p)", (testFunction, functionType) => {
151166
util.testFunction`
152167
function returnsFunction(): ${functionType} {

0 commit comments

Comments
 (0)