我已经为下面的函数编写了测试用例(我省略了很多不必要的代码,只提供了必要的东西,但如果你需要任何其他信息,请告诉我)。
static getLibs() {
return new Promise((resolve, reject) => {
const instance = new LibClass();
instance.loadLibs().then((libs) => {
if (!libs) {
return LibUtils.createLib();
} else {
return Promise.resolve([]);
}
}).then(resolve).catch((err) => {
//log stuff here
})
})
}
export default class LibClass {
//constructor
//method
createLib() {
return new Promise(() => {
//some stuff
})
}
}Run Code Online (Sandbox Code Playgroud)
describe('Library', () => {
it('should get libs', () => {
let obj = new LibClass();
let mstub = sinon.stub(obj, 'loadLibs').returns(Promise.resolve('success'));
return LibWrapper.getLibs().then((res) => …Run Code Online (Sandbox Code Playgroud)