简体   繁体   中英

Chutzpah - AngularJS testing with jasmine and TypeScript

I am using Angular 1.4.9 with Jasmine 2.2.0 and Chutzpah 4.2.0 with both my Angular code and unit tests in TypeScript in Visual Studio 2015 Update 1.

My issue is identical to that posted previously TypeScript - jasmine - Chutzpah - AngularJS . I have attempted to implement the accepted answer over there (adding the /// <chutzpah_reference /> to the test typescript file for angular, angular mocks, and angular ui), however I still receive the error:

Can't find variable: angular in file X

I have also tried adding the js files to the chutzpah.json file after removing the above chutzpah reference includes (see below)

After this I enabled Chutzpah logging from Visual Studio Options-> Chutzpah -> Enable Chutzpah Tracing, re run the tests, and confirmed that the JS files were indeed being picked-up. I am also able to run others tests in typescript with Chutzpah that do not have angular dependencies.

Any ideas?

{
  "Framework": "jasmine",
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ]
  },
  "References": [
    {
      "Includes": [ "*/../project/app/*.ts", "../project/scripts/*.js" ],
      "Excludes": [ "*/../project/app/*.d.ts" ]
    }
  ],
  "Tests": [
    {
      "Includes": [ "*/AppTests/*.ts" ],
      "Excludes": [ "*/AppTests/*.d.ts" ]
    }
  ]
}

Project directory structure is rather standard: SLN file has, among others, 2 projects one for the Web App, and another for the Web App Tests.

See https://github.com/mmanela/chutzpah/wiki/Breaking-change-to-nested-reference-comments-in-version-4.1 :

Chutzpah 4.1 made a change to when it will scan your file for /// <reference comments. Originally, Chutzpah did not have the chutzpah.json settings file and would only find references by cracking open your file and parsing for reference comments. However, since the chutzpah.json file was added the recommended way for declaring references is to use the reference section and not the file comments. The problem was that even if you used a chutzpah.json it would still open your files and parse them for the comments (which has a performance cost). In order to solve this problem version 4.1 changes the way expanding references works.

  1. If you do not use a chutzpah.json file to specify your tests (NOT RECOMMENDED), then nothing changes. Your reference comments are still parsed.

  2. If you specify a tests setting AND want to still expand nested references must set the ExpandReferenceComments setting to true. For example:

    "Tests": [ { "Path": "Tests", "Includes": [" .Spec. "], "ExpandReferenceComments": "true" } ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM