Trying to migrate from jasmine 1.3 to 2.0...

Topics: General
Apr 22, 2014 at 10:11 PM
Not sure if this was the correct forum for this, but my attempts at getting typescript working with the 2.0 jasmine.d.ts typefile aren't going as expected.
I've updated the jasmine typescript definition file with the lastest 2.0 version from here:

As such, I was expecting see new/changed functionality/syntax added within my typescript scripts (within the ts editor in VS 2013) to do such things as 'jasmine.addmatchers', etc...
But trying to use that is undefined as far as the editor is concerned.
Can anyone help on getting this worked out?

Apr 23, 2014 at 12:59 AM
Edited Apr 23, 2014 at 1:27 AM
There is no "addmatchers" in the "jasmine" module space. It's in the "Spec" interface. Can you post some example code?

I took a quick peek at the jasmine.js file and I only see a reference to "window.jasmineRequire", not "window.jasmine"...?

Anyhow, you are only defining interfaces, and the interfaces only look like they are mixing both static and instance declarations. For example, you could do this:
    interface Any {
        jasmineMatches(other: any): boolean;
        jasmineToString(): string;
    var Any: {
        new (expectedClass: any): Any;
or this
    class Any {

        constructor(expectedClass: any);

        jasmineMatches(other: any): boolean;
        jasmineToString(): string;
You had this:
   interface Any {
        new (expectedClass: any): Any;
        jasmineMatches(other: any): boolean;
        jasmineToString(): string;
Which is not correct. You are saying here that an object instance of type "Any" is a constructor function (because of "new (...)") but also that the FUNCTION itself (static object) contains the listed instance methods (which doesn't seem to be the case in the file I saw). As well, you cannot reference "interface Any" in actual JS code (it's only a type).
Apr 23, 2014 at 4:37 AM
well, on checking around on how to do the migration.. I've found this: and

both of which would appear to be wrong.
Apr 23, 2014 at 8:58 AM
Is there a specific question in all this? It would be better to try fixing it up as I explained and post code to get more help (unless you are looking for someone to read the whole spec for you and create the definitions ;) ). It's really not that hard - just take it one type at a time. Look at other .d.ts files for examples (such as lib.d.ts).
Apr 23, 2014 at 5:08 PM
yes, I''m sorry, I should have been a bit more clear on my question.
I'm having to move my 1.3 jasmine custom matchers to 2.0, so for example this currently:
beforeEach(function () {

var toBeDivisibleByTwo = function () {
    return (this.actual % 2) === 0;
needs to be migrated.
those two bits of docs I previously referenced show two different approaches on using the 2.0 matcher interface that don't seem to be correct.

does that clarify my question?
Apr 23, 2014 at 5:48 PM
Edited Apr 23, 2014 at 6:27 PM
While I can't comment on the migration process, I can only comment on the TypeScript definition file. The new migration shows this example:
 beforeEach(function() {
The "jasmine.d.ts" file (from Definitely Typed) doesn't seem correct. As I stated earlier, there is no "addMatchers" function declared directly in the "jasmine" module. How should "jasmine.addMatchers" be expected to work? For that matter, the "jasmine.js" file doesn't even create a "jasmine" variable in the global scope - I only see "window.jasmineRequire".

The definition file needs to be corrected first before you post code to be migrated.

(FYI: Just for the record, I've never heard of Jasmine until now; I just read the .js file ;) )
Apr 23, 2014 at 6:04 PM
Okay, granted... the definition file appears incorrect. So no one using typescript and jasmine unit tests has been able to move from 1.3 to 2.0 (assuming they need custom matchers and/or async support) without some sort of hackery of the description file(s)?
Apr 28, 2014 at 11:38 PM
There is no guarantee the declaration on DefinitelyTyped are correct or up-2-date. Looks like nobody got around to updating jasmine to 2.0, or they didn't use this feature.

Hackery in the declaration file is part of working with TypeScript, but we can all pool effort by pushing fixes back to DT.