2016-05-23 42 views
2

我想讓Jasmine與Visual Studio Test Explorer一起工作。 所以,我的測試文件是這樣的:AngularJS,Jasmine和Visual Studio 2015測試瀏覽器

/// <reference path="../wwwroot/lib/angular/angular.min.js" /> 
/// <reference path="../wwwroot/lib/angular-mocks/angular-mocks.js" /> 
/// <reference path="../wwwroot/lib/jasmine/lib/jasmine-core/jasmine.js" /> 

/// <reference path="../wwwroot/lib/angular-arrays/dist/angular.arrays.js" /> 
/// <reference path="../wwwroot/lib/angular-simple-cache/dist/simplecache.js" /> 
/// <reference path="../wwwroot/lib/angular-toastr/dist/angular-toastr.tpls.min.js" /> 
/// <reference path="../wwwroot/lib/ng-file-upload/ng-file-upload.min.js" /> 

/// <reference path="../app/common/common.js" /> 
/// <reference path="../app/common/services.js" /> 

var _sharedProductHandler, 
    _pricingProducts, 
    _availabilityProducts; 

beforeEach(module('piiick.common')); 
beforeEach(inject(['SharedProductHandler', function (sharedProductHandler) { 
    _sharedProductHandler = sharedProductHandler; 

    _pricingProducts = [{ 
     productId: 0 
    }]; 
    _availabilityProducts = [{ 
     productId: 0 
    }]; 
}])); 

describe('Service: SharedProductService', function() { 
    it('We have a list of pricing products', function() { 
     expect(_pricingProducts.length).toBeGreaterThan(0); 
    }); 

    it('We have a list of availability products', function() { 
     expect(_availabilityProducts.length).toBeGreaterThan(0); 
    }); 
}); 

如果我在瀏覽器中打開測試運行正常。但我希望它們出現在測試瀏覽器中。我爲測試瀏覽器安裝了Chutzpah適配器,但我的測試並未出現在那裏。 我read that you can use a chutzpah.json file to add settings,所以我做到了,但我無法讓我的測試出現在測試瀏覽器中。 我認爲值得一提的是我正在使用Visual Studio 2015.

有誰知道我如何讓我的測試顯示在測試資源管理器中?

回答

1

對,我工作了這一點。該chutzpah.json文件需要在根(它可以在任何地方,而路徑設置必須相對於地方JSON文件是 礦是這樣的:。

{ 
    "Framework": "jasmine", 
    "References": [ 
    { "Path": "wwwroot/lib/angular/angular.min.js" }, 
    { "Path": "wwwroot/lib/angular-mocks/angular-mocks.js" }, 
    { "Path": "wwwroot/lib/jasmine/lib/jasmine-core/jasmine.js" }, 

    { "Path": "wwwroot/lib/angular-arrays/dist/angular.arrays.js" }, 
    { "Path": "wwwroot/lib/angular-simple-cache/dist/simplecache.js" }, 
    { "Path": "wwwroot/lib/angular-toastr/dist/angular-toastr.tpls.min.js" }, 
    { "Path": "wwwroot/lib/ng-file-upload/ng-file-upload.min.js" }, 

    { "Path": "app/common/common.js" }, 
    { "Path": "app/common/services.js" } 
    ], 

    "Tests": [ 
    { "Path": "tests" } 
    ] 
} 

規範文件將不再需要任何引用,這樣就可以是這樣的:

var _sharedProductHandler, 
    _pricingProducts, 
    _availabilityProducts; 

beforeEach(module('piiick.common')); 
beforeEach(inject(['SharedProductHandler', function (sharedProductHandler) { 
    _sharedProductHandler = sharedProductHandler; 

    _pricingProducts = [{ 
     productId: 0 
    }]; 
    _availabilityProducts = [{ 
     productId: 0 
    }]; 
}])); 

describe('Service: SharedProductService', function() { 
    it('We have a list of pricing products', function() { 
     expect(_pricingProducts.length).toBeGreaterThan(0); 
    }); 

    it('We have a list of availability products', function() { 
     expect(_availabilityProducts.length).toBeGreaterThan(0); 
    }); 
}); 

,只是爲我自己參考,bower.json只需要兩個:

{ 
    "name": "ASP.NET", 
    "private": true, 
    "dependencies": { 
    "angular-mocks": "^1.5.5", 
    "jasmine": "^2.4.1" 
    }, 
    "ignore": [ 
    "tests" 
    ] 
} 
+0

很高興你知道了! –

相關問題