Skip to content

Commit

Permalink
put Type 'ExpectArray<number>' has no call signatures on same line
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Oct 3, 2023
1 parent 77051e5 commit c6d62c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
4 changes: 3 additions & 1 deletion packages/vitest/src/typecheck/typechecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export class Typechecker {
const suiteErrors = errors.map((info) => {
const limit = Error.stackTraceLimit
Error.stackTraceLimit = 0
const error = new TypeCheckError(info.errMsg, [
// Some expect-type errors have the most useful information on the second line e.g. `This expression is not callable.\n Type 'ExpectString<number>' has no call signatures.`
const errMsg = info.errMsg.replace(/\n {2}(Type .* has no call signatures)/g, ' $1')
const error = new TypeCheckError(errMsg, [
{
file: filepath,
line: info.line,
Expand Down
38 changes: 19 additions & 19 deletions test/typescript/test/__snapshots__/runner.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should fail > typecheck files 1`] = `
"TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'. ❯ only.test-d.ts:4:33
TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectUndefined<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'. ❯ fail.test-d.ts:4:33
TypeCheckError: Unused '@ts-expect-error' directive. ❯ expect-error.test-d.ts:4:3
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures."
"TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.
TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectUndefined<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.
TypeCheckError: Unused '@ts-expect-error' directive.
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures."
`;
exports[`should fail > typecheck files 2`] = `
" FAIL fail.test-d.ts > nested suite
TypeCheckError: This expression is not callable.
Type 'ExpectVoid<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
❯ fail.test-d.ts:15:19
13| })
14|
15| expectTypeOf(1).toBeVoid()
| ^"
| ^
16| })"
`;
exports[`should fail > typecheck files 3`] = `
Expand All @@ -45,35 +45,35 @@ TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string,
exports[`should fail > typecheck files 5`] = `
" FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2
TypeCheckError: This expression is not callable.
Type 'ExpectVoid<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
❯ fail.test-d.ts:10:23
8| describe('nested 2', () => {
9| test('failing test 2', () => {
10| expectTypeOf(1).toBeVoid()
| ^"
| ^
11| expectTypeOf(1).toBeUndefined()"
`;
exports[`should fail > typecheck files 6`] = `
" FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2
TypeCheckError: This expression is not callable.
Type 'ExpectUndefined<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectUndefined<number>' has no call signatures.
❯ fail.test-d.ts:11:23
9| test('failing test 2', () => {
10| expectTypeOf(1).toBeVoid()
11| expectTypeOf(1).toBeUndefined()
| ^"
| ^
12| })"
`;
exports[`should fail > typecheck files 7`] = `
" FAIL js-fail.test-d.js > js test fails
TypeCheckError: This expression is not callable.
Type 'ExpectArray<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has no call signatures.
❯ js-fail.test-d.js:6:19
4|
5| test('js test fails', () => {
6| expectTypeOf(1).toBeArray()
| ^"
| ^
7| })"
`;
exports[`should fail > typecheck files 8`] = `
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('should fail', async () => {
expect(stderr).toBeTruthy()
const lines = String(stderr).split(/\n/g)
const msg = lines
.flatMap((line, i, array) => line.includes('TypeCheckError: ') ? [[line + array[i + 1]].filter(Boolean).join('\n')] : [])
.filter(i => i.includes('TypeCheckError: '))
.reverse()
.join('\n')
.trim()
Expand Down

0 comments on commit c6d62c5

Please sign in to comment.