-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report missing diagnostic codes when using
expectError
(#178)
- Loading branch information
1 parent
168de40
commit b4503d0
Showing
10 changed files
with
107 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import {verify} from './fixtures/utils'; | ||
import tsd from '..'; | ||
|
||
test('expectError for classes', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/classes')}); | ||
|
||
verify(t, diagnostics, []); | ||
}); | ||
|
||
test('expectError for functions', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/functions')}); | ||
|
||
verify(t, diagnostics, [ | ||
[5, 0, 'error', 'Expected an error, but found none.'] | ||
]); | ||
}); | ||
|
||
test('expectError for generics', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/generics')}); | ||
|
||
verify(t, diagnostics, []); | ||
}); | ||
|
||
test('expectError should not ignore syntactical errors', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/syntax')}); | ||
|
||
verify(t, diagnostics, [ | ||
[4, 29, 'error', '\')\' expected.'], | ||
[5, 22, 'error', '\',\' expected.'], | ||
]); | ||
}); | ||
|
||
test('expectError for values', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/values')}); | ||
|
||
verify(t, diagnostics, [ | ||
[5, 0, 'error', 'Expected an error, but found none.'] | ||
]); | ||
}); | ||
|
||
test('expectError for values (noImplicitAny disabled)', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/values-disabled-no-implicit-any')}); | ||
|
||
verify(t, diagnostics, []); | ||
}); | ||
|
||
test('expectError for values (exactOptionalPropertyTypes enabled)', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/enabled-exact-optional-property-types')}); | ||
|
||
verify(t, diagnostics, []); | ||
}); | ||
|
||
test('expectError should report missing diagnostic codes', async t => { | ||
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/expect-error/missing-diagnostic-code')}); | ||
|
||
verify(t, diagnostics, [ | ||
[8, 12, 'error', 'Cannot find name \'undeclared\'.'], | ||
[5, 0, 'error', 'Expected an error, but found none.'], | ||
[8, 0, 'error', 'Found an error that tsd does not currently support (`ts2304`), consider creating an issue on GitHub.'], | ||
]); | ||
}); |
6 changes: 6 additions & 0 deletions
6
source/test/fixtures/expect-error/missing-diagnostic-code/index.d.ts
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,6 @@ | ||
declare const one: { | ||
(foo: string, bar: string): string; | ||
(foo: number, bar: number): number; | ||
}; | ||
|
||
export default one; |
3 changes: 3 additions & 0 deletions
3
source/test/fixtures/expect-error/missing-diagnostic-code/index.js
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,3 @@ | ||
module.exports.default = (foo, bar) => { | ||
return foo + bar; | ||
}; |
8 changes: 8 additions & 0 deletions
8
source/test/fixtures/expect-error/missing-diagnostic-code/index.test-d.ts
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,8 @@ | ||
import {expectError} from '../../../..'; | ||
import one from '.'; | ||
|
||
// 'Expected an error, but found none.' | ||
expectError(one('foo', 'bar')); | ||
|
||
// 'Found an error that tsd does not currently support (`ts2304`), consider creating an issue on GitHub.' | ||
expectError(undeclared = one('foo', 'bar')); |
3 changes: 3 additions & 0 deletions
3
source/test/fixtures/expect-error/missing-diagnostic-code/package.json
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,3 @@ | ||
{ | ||
"name": "foo" | ||
} |
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