测试 Factory toBeDefined 时出错
Error when testing Factory toBeDefined
describe('Tickers Factory:', function() {
var tickersFactory, tickerContainer, tickerType, chartIsReady;
beforeEach(function() {
module('tickersFactory');
});
beforeEach(inject(function(_tickersFactory_) {
tickersFactory = _tickersFactory_;
}));
it('tickersFactory should be defined', function() {
expect(tickersFactory).toBeDefined();
});
});
我正在尝试测试我的 tickersFactory
服务是否已定义,我的 Jasmine 运行 没问题,但是上面的代码抛出以下错误:
TickersFactory
////////////////////////////////////////////////////////////////////////////////
/**
* @name tickersFactory
* @namespace Factories
* @desc Stores the global ticker and ticker type
*/
var tickersFactory = angular
.module('tickersFactory', [])
.factory('TickersFactory', factory);
factory.$inject = [
'$rootScope',
'ApiFactory',
'GetTickersFactory'
];
function factory(
$rootScope,
ApiFactory,
GetTickersFactory) {
/** Init TickersFactory scope */
/** ----------------------------------------------------------------- */
var tickerContainer = {},
tickerType = {},
chartIsReady = false;
var tickersFactory = {
returnChartReady : returnChartReady,
storeTicker : storeTicker,
getTicker : getTicker,
storeTickerType : storeTickerType,
getTickerType : getTickerType,
initTickersPanel : initTickersPanel
};
return tickersFactory;
////////////////////////////////////////////////////////////////////////
function returnChartReady() {
return chartIsReady;
}
您要测试的工厂是 _TickersFactory_
,因此您需要使用 _TickersFactory_
_ 而不是 _tickersFactory_
.
来注入它
从图像上看有点难以分辨,但您似乎遇到了 错误:$injector:unpr
未知提供商
describe('Tickers Factory:', function() {
var tickersFactory, tickerContainer, tickerType, chartIsReady;
beforeEach(function() {
module('tickersFactory');
});
beforeEach(inject(function(_tickersFactory_) {
tickersFactory = _tickersFactory_;
}));
it('tickersFactory should be defined', function() {
expect(tickersFactory).toBeDefined();
});
});
我正在尝试测试我的 tickersFactory
服务是否已定义,我的 Jasmine 运行 没问题,但是上面的代码抛出以下错误:
TickersFactory
////////////////////////////////////////////////////////////////////////////////
/**
* @name tickersFactory
* @namespace Factories
* @desc Stores the global ticker and ticker type
*/
var tickersFactory = angular
.module('tickersFactory', [])
.factory('TickersFactory', factory);
factory.$inject = [
'$rootScope',
'ApiFactory',
'GetTickersFactory'
];
function factory(
$rootScope,
ApiFactory,
GetTickersFactory) {
/** Init TickersFactory scope */
/** ----------------------------------------------------------------- */
var tickerContainer = {},
tickerType = {},
chartIsReady = false;
var tickersFactory = {
returnChartReady : returnChartReady,
storeTicker : storeTicker,
getTicker : getTicker,
storeTickerType : storeTickerType,
getTickerType : getTickerType,
initTickersPanel : initTickersPanel
};
return tickersFactory;
////////////////////////////////////////////////////////////////////////
function returnChartReady() {
return chartIsReady;
}
您要测试的工厂是 _TickersFactory_
,因此您需要使用 _TickersFactory_
_ 而不是 _tickersFactory_
.
从图像上看有点难以分辨,但您似乎遇到了 错误:$injector:unpr 未知提供商