0
のは、私はこのようなエクスポートモジュールがあるとしましょう: スロンは私のスタブをなぜ認識しないのですか?
module.exports = mymodule;
はその後、私のテストファイルで、私はモジュールを必要とし、それをスタブ。
var mymodule = require('./mymodule');
describe('Job gets sports data from API', function(){
context('When there is a GET request', function(){
it('will call callback after getting response', sinon.test(function(done){
var getRequest = sinon.stub(mymodule, 'getSports');
getRequest.yields();
var callback = sinon.spy();
mymodule.getSports(callback);
sinon.assert.calledOnce(callback);
done();
}));
});
});
これは動作し、テストに合格します。しかし、複数のオブジェクトをエクスポートする必要がある場合は、すべてが故障します。以下を参照してください:
module.exports = {
api: getSports,
other: other
};
は、その後、私は私のテストコードを調整してみてください。この場合
var mymodule = require('./mymodule');
describe('Job gets sports data from API', function(){
context('When there is a GET request', function(){
it('will call callback after getting response', sinon.test(function(done){
var getRequest = sinon.stub(mymodule.api, 'getSports');
getRequest.yields();
var callback = sinon.spy();
mymodule.api.getSports(callback);
sinon.assert.calledOnce(callback);
done();
}));
});
});
、私のテストクラップスを行います。スタブコードを変更するにはどうすればよいですか?ありがとう! mymodule.api
自体がgetSports
メソッドを持っていないように見えるこの
module.exports = {
api: getSports,
other: other
};
に基づいて