私はいくつかのジャスミンテストスイートを持っていますが、そのうちのいくつかは実装したサービスを使用しています。ジャスミンのサービス行動は何ですか?私は私のサービスに対していくつかのテストを実行しているとき、私がやっていることは他のunitTestsに影響を与えることに気付きました。 unitTestは完全に独立していなければならないので、これは起こり得ませんでした。すなわちジャスミンサービスの振る舞い
it('Given my service with list populated when cleanList then getList return empty list', function(){
myService.populateList(_myData_);
expect(myService.getList().length).toBe(5);
myService.cleanList();
expect(myService.getList().length).toBe(0);
expect(myService.getList()).toEqual([]);
});
私は他の中の別の試験前の試験は別の完全に異なるJSスクリプトに記述することを実行した場合、私は人口が、このテストはそれをきれいにしているそのリストを使用することが予想されるので、失敗に私の他のテスト開始を提出。私のアプリのようにここのサービスはシングルトンですか?記述スイートごとにこれらのサービスの独立したインスタンスを作成できますか?
これは私がサービスのこれらの種類を使用している方法です。
(function(){
'use strict';
var _data_ = require('../../../../json/dataMock.json');
fdescribe('MyApp wizard:', function(){
var controller, createController;
var modalInstance = { close: function(){}, dismiss: function(){} };
var myService;
beforeEach(function(){
angular.mock.module('myapp.ui.apps.wizard');
angular.mock.module('myapp.ui.apps.wizard.service');
});
beforeEach(inject(function($injector, $controller, $rootScope, _$sce_, _myService_){
myService = _myService_;
createController = function() {
return $controller('MaintenancesWizardController', {
$rootScope: $rootScope,
$uibModalInstance: modalInstance,
data: _data_,
$sce: _$sce_,
myService: _myService_
});
}
}));
it('this test fails if the one before is executed', function(){
controller = createController();
expect(myService.getList().length).toBe(5);
});
あなたはmyserviceをテストしようとしていますか?実際にサービスを呼び出して値を変更しないように、あなたのサービスにスパイを使うことができます。 –
@MukulJayaprakash私はちょうど何が起こったのか発見した!私の答えを読む – acostela