Definitelytyped: @types/jasmine - Spy.withArgs() method missing

Created on 7 Aug 2018  Â·  13Comments  Â·  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the @types/jasmine@latest package and had problems.

Authors: @borisyankov, @theodorejb, @davidparsson, @gmoothart, @lukas-zech-software, @Engineer2B


In the documentation for Jasmine 3.1, the Spy class contains the withArgs instance method. This is missing from the latest version of @types/jasmine.

All 13 comments

@borisyankov, @theodorejb, @davidparsson, @gmoothart, @lukas-zech-software, @Engineer2B

Is anyone able to take a look at this?

Seems reasonable; can you send a PR?

On Tue, Sep 4, 2018 at 10:12 AM Jacob Stamm notifications@github.com
wrote:

@borisyankov https://github.com/borisyankov, @theodorejb
https://github.com/theodorejb, @davidparsson
https://github.com/davidparsson, @gmoothart
https://github.com/gmoothart, @lukas-zech-software
https://github.com/lukas-zech-software, @Engineer2B
https://github.com/Engineer2B

Is anyone able to take a look at this?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/27938#issuecomment-418446721,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAMm41ozZfseXk3f8J4OsOxzO40g15Zks5uXrSAgaJpZM4VyL3H
.

@gmoothart I'll submit one shortly. I'm an NPM noob, though... how do I increase the version from 2.8.8? I think we should move it to 3.1.0 for parity with Jasmine

Versoning is not managed well by DefinitelyTyped. Following the pattern in
the jasmine typings, though, you should copy everything to a "v2" folder
and then rev the main typings file to v3 with your change.

Gabe

On Thu, Sep 6, 2018 at 7:55 AM Jacob Stamm notifications@github.com wrote:

@gmoothart https://github.com/gmoothart I'll submit one shortly. I'm an
NPM noob, though... how do I increase they version from 2.8.8? I think we
should move it to 3.1.0 for parity with Jasmine

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/27938#issuecomment-419124214,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAMm2rIIh0bEihMM5OZ9KTgKB2vxCbKks5uYTdegaJpZM4VyL3H
.

Gotcha. So is the version number of the package some managed process that's out of our control? Just wondering how people get the correct version that corresponds to the library they're using without combing the source code for mentions of which version it corresponds to.

The jasmine version is just a comment in the typings file, which you linked
to. In practice most typings changes are additive and not breaking changes
(as is the case with your proposed change) so this isn't too bad. You are
not https://github.com/DefinitelyTyped/DefinitelyTyped/issues/7719 alone
https://stackoverflow.com/questions/44848828/typescript-types-version-related-to-library-version
in
thinking this is insufficient but it is just the way it is.

On Thu, Sep 6, 2018 at 8:29 AM Jacob Stamm notifications@github.com wrote:

Gotcha. So is the version number of the package some managed process
that's out of our control? Just wondering how people get the correct
version that corresponds to the library they're using without combing the
source code for mentions of which version it corresponds to
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/5344bfc80508c53a23dae37b860fb0c905ff7b24/types/jasmine/index.d.ts#L1
.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/27938#issuecomment-419137549,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAMm09w5ufgX10FiqZ9NaSqN9ctFLsaks5uYT9SgaJpZM4VyL3H
.

Thanks for the info!

So I'm working on a 3.0 version (because that's the first one where withArgs was introduced) and I'm making some quality of life changes as well to some of the method signatures and JSDoc comments to adhere to the official version docs, but I'm noticing some peculiarities that make we wonder how accurate their official docs are. Take xit, for instance. If it's just a temporarily disabled it, why should it change it's method signature by dropping the timeout param? Same for fit — why should it make the testFunction param required when it's optional for it?

Based on your experience with this project, should I take the word of these docs and make the typings conform to them, or do I need to dig into the actual Jasmine source code (and maybe test it out) to make sure conforming the typings to the docs won't result in runtime errors? I'd appreciate the feedback of any prior authors.

Not a prior author, but I have noticed a number of places where the types do not match the source.

For example, jasmine's spy strategy .and.throwError takes an Error or a string, but these type definitions have it as just a string (both for jasmine 2.8). To your point however, even the official Jasmine documentation gets it right.

I've come across a few cases like this, so I suspect there are more. I think it'd be a marked improvement to just bring these types in line with what the official docs say. Those docs appear to be generated directly from the JSDoc in the source, so running something like https://www.npmjs.com/package/tsd-jsdoc and doing a diff may be an easier way to spot issues.

30872 closes this.

For example, jasmine's spy strategy .and.throwError takes an Error or a string, but these type definitions have it as just a string (both for jasmine 2.8).

I'm going to do a PR for this now.

this can be closed

Is this supposed to allow us to use withArgs() on objects created with createSpyObj()?

I'm using jasmine 3.4.0:

$ npm view jasmine version
3.4.0

I create my spy:

mockAccessResolverService =
      jasmine.createSpyObj<AccessResolverService>('AccessResolverService', ['resolveAccessByEntitlements', 'resolveAccess']);

When I try to define the behavior for a method:

mockAccessResolverService.resolveAccess.withArgs([ADD_EDIT_PERMISSION]).and.returnValue(Observable.of(false));

I get:

TypeError: mockAccessResolverService.resolveAccess.withArgs is not a function

@Blackbaud-JasonBodnar Please ensure to install the latest @types/jasmine, as your sample works perfectly fine for me.

@stamminator Please close the issue if solved.

Was this page helpful?
0 / 5 - 0 ratings