-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to write tests for source code in .ts files? #32
Comments
So what you want is actually write a test which verifies that a certain function call only accepts an array of strings and nothing else? That's not yet supported right now. The main focus is type definitions but I don't see a reason why this wouldn't be supported. |
Correct @SamVerschueren. I have |
I too came here looking for this functionality. 🙂 (As a sidenote, it actually wasn't clear to me that this library is only for |
For what it's worth, I was able to work around this by creating an empty |
Something that may also help here is more flexibility around specifying which Definitely a separate issue though. |
- Adds the folder test-d/ to contain the types - we are using tsd to check the types - Added a test:types script to package.json - Apparently we need a root index.d.ts for tsd to work tsdjs/tsd#32 (comment)
- Adds the folder test-d/ to contain the types - we are using tsd to check the types - Added a test:types script to package.json - Apparently we need a root index.d.ts for tsd to work tsdjs/tsd#32 (comment)
- Adds the folder test-d/ to contain the types - we are using tsd to check the types - Added a test:types script to package.json - Apparently we need a root index.d.ts for tsd to work tsdjs/tsd#32 (comment)
I develop libraries that are mostly about introducing advanced type safety features by making use of compiler inference. I'm using dtslint and got fed up with weird file structure requirements and worarounds, insufficient type equality checks etc. I found |
I suggest using expect-type to write tests for |
I'm also trying to use But for now, I have come up with a hackish workaround. WORKAROUND!!!In my project, I added a dummy nested "project" directory named {
"types": "dummy.d.ts",
"tsd": {
"directory": "../src"
}
} Then my script in my real {
"scripts": {
"tsd": "tsd tsd_project"
}
} This satisfies |
@UselessPickles, thank you! This worked for me!! |
I'd love to be able to use Here's a quick use case of the kind of thing I'd like to be able to write: import {MouseEvent as ReactMouseEvent} from 'react';
import {expectType} from 'tsd';
import {Button} from './Button';
<Button
onClick={e => {
expectType<ReactMouseEvent<HTMLButtonElement, MouseEvent>>(e);
}}
/>
<Button
as="a"
onClick={e => {
expectType<ReactMouseEvent<HTMLAnchorElement, MouseEvent>>(e);
}}
/> |
Some of this was remnants of the past. Some was me not quite understanding script vs. module. Some was me misunderstanding what was actually going on in Tsd. It turns out that Tsd was just incidentally working, but I was never using it according to their intentions. You don't really test *.ts files with Tsd [1], but I happen to place compile output along side of them, hence "incidentally working". Now I am merely relying on TS compiler's diagnostic output, which is really what Tsd does anyway. [1] tsdjs/tsd#32
The docs provide an example of writing a test against a declaration file, but what if you want to instead write a test against a source
.ts
file? I tried doing this but I couldn't get it to work. Is this not yet supported?The text was updated successfully, but these errors were encountered: