我正在尝试为调用 OVH api 的函数编写一个简单的测试。
我不明白,我的sinon.js 存根不会“转移” ovh api的requestPromised方法。sinon.js 的存根与类对象的工作方式不同?
我的功能(myOvhApi.js):
const ovh = require('ovh')({
endpoint: 'Endpoint',
appKey: 'AppKey',
appSecret: 'appSecret',
consumerKey: 'ConsumerKey'
})
exports.myFunction = async ( ipAdress, subDomain, ovhDynDNSId ) => {
try{
await ovh.requestPromised( 'PUT', `/domain/zone/${zone}/dynHost/record/${ovhDynDNSId}`,
{
'ip': ipAdress,
'subDomain': subDomain
})
} catch (error) {
console.log(error)
}
return true
}
我的测试:
const ovh = require('ovh')
const myOvhApi = require('myOvhApi')
describe('description', () => {
it('description', async () => {
const zone = 'mydomain.com'
const ovhDynDNSId = '12345'
const ipAdress = '127.0.0.1'
const subDomain = 'subDomain'
sinon.stub( ovh, 'requestPromised' ).returns(true)
const expectation = await myOvhApi.myFunction ( ovhDynDNSId, ipAdress, subDomain )
expect( expectation ).to.equal(true)
})
})
谢谢