Skip to content

Add stronger typings to jasmine spys#33860

Merged
sheetalkamat merged 2 commits intoDefinitelyTyped:masterfrom
kolodny:better-jasmine-types-3-1
Mar 19, 2019
Merged

Add stronger typings to jasmine spys#33860
sheetalkamat merged 2 commits intoDefinitelyTyped:masterfrom
kolodny:better-jasmine-types-3-1

Conversation

@kolodny
Copy link
Copy Markdown
Contributor

@kolodny kolodny commented Mar 14, 2019

I added stronger typings for jasmine spys along with the createSpyObj, spyOn and calls interfaces. This relies heavily on typescript 3.1 so I've created a typesVersions for that. This was mostly a move operation but the main highlights are at https://github.com/kolodny/DefinitelyTyped/blob/better-jasmine-types-3-1/types/jasmine/ts3.1/jasmine-tests.ts#L1165-L1222

I also needed to fix jasmine-ajax-tests.ts since they attempt to use an incomplete object for the returnValue (which is something the type system should catch, so yay!)

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Provide a URL to documentation or source code which provides context for the suggested changes: <>
Increase the version number in the header if appropriate.
If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

@kolodny kolodny requested a review from borisyankov as a code owner March 14, 2019 00:37
return `${num} and ${str}`;
});
it('has a typed returnValue', () => {
// $ExpectType (val: string) => Spy<(num: number, str: string) => string>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have done:

// $ExpectType string
let argType: Parameters<typeof spyObj.method.and.returnValue>[0];

and the same for below but I figured this may be simpler

spy.calls.first().returnValue; // $ExpectType string
});
it('has a typed callFake', () => {
// $ExpectType (fn: (num: number, str: string) => string) => Spy<(num: number, str: string) => string>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block can be rewritten as

type FakeFnArg = Parameters<typeof spy.and.callFake>[0]
let args: Parameters<FakeFnArg> // $ExpectType [number, string]
let returnValue: ReturnType<FakeFnArg> // $ExpectType string

Let me know if that's better

@kolodny
Copy link
Copy Markdown
Contributor Author

kolodny commented Mar 14, 2019

EDIT

This is now sorted via https://github.com/DefinitelyTyped/DefinitelyTyped/pull/33860/files#diff-964b6bf718830679bd417defc1a8ce48


Previous content:

This PR errors with:

Error in saywhen
Error: /home/travis/build/DefinitelyTyped/DefinitelyTyped/types/saywhen/saywhen-tests.ts:3:1
ERROR: 3:1  expect  Expected type to be:
  CallHandler<Spy>
got:
  CallHandler<Spy<InferableFunction>>
ERROR: 4:1  expect  Expected type to be:
  Proxy<Spy>
got:
  Proxy<Spy<InferableFunction>>

However if I make that change I then get this error:

Error in saywhen
Error: /Users/mkolodny/projects/DefinitelyTyped/types/saywhen/saywhen-tests.ts:3:1
ERROR: 3:1  expect  Expected type to be:
  CallHandler<Spy<InferableFunction>>
got:
  CallHandler<Spy>
ERROR: 4:1  expect  Expected type to be:
  Proxy<Spy<InferableFunction>>
got:
  Proxy<Spy>

I'm not sure what to do about that. This may be related to microsoft/dtslint#192

@typescript-bot typescript-bot added New Definition This PR creates a new definition package. Popular package This PR affects a popular package (as counted by NPM download counts). The Travis CI build failed labels Mar 14, 2019
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Mar 14, 2019

@kolodny Thank you for submitting this PR!

Because this is a new definition, a DefinitelyTyped maintainer will be reviewing this PR in the next few days once the Travis CI build passes.

In the meantime, if the build fails or a merge conflict occurs, I'll let you know. Have a nice day!

@typescript-bot
Copy link
Copy Markdown
Contributor

@kolodny The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@weswigham
Copy link
Copy Markdown
Contributor

cc @borisyankov @theodorejb @davidparsson @gmoothart @lukas-zech-software @Engineer2B @cyungmann @Roaders @devoto13 @FDIM @pe8ter y'all should have a chance to review this before it goes in, but the bot didn't ping you, since apparently it doesn't recognize a typesVersions addition as a kind of edit.

@typescript-bot typescript-bot added the Unmerged The author did not merge the PR when it was ready. label Mar 19, 2019
@typescript-bot
Copy link
Copy Markdown
Contributor

After 5 days, no one has reviewed the PR 😞. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience!

@sheetalkamat sheetalkamat merged commit b9d9f51 into DefinitelyTyped:master Mar 19, 2019
@typescript-bot
Copy link
Copy Markdown
Contributor

I just published @types/[email protected] to npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Definition This PR creates a new definition package. Popular package This PR affects a popular package (as counted by NPM download counts). Unmerged The author did not merge the PR when it was ready.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants