наконец, мне пришлось изменить модуль на синтаксис ECMAScript 6.
, поэтому мой новый модуль выглядит следующим образом:
module.js
export function callSoap(id){
....//some code
return new Promise((resolve,reject) =>{
return resolve("whatever");
}
}
когда я перехожу на синтаксис ECMAScript 6, я внедряю babel-cli для компиляции в EC5, поэтому индекс меняется с:
var soapModule = require('./module/module');
на
var soapModule = require('./lib/module'); //<-- this is the build output folder
затем,юнит-тест выглядит так:
import MyClass from "../src/my-class";
import {soapModule} from "soap-client";
import sinon from 'sinon';
describe("Test MyClass",()=>{
let myclass;
let stub;
before(()=>{
myclass = new MyClass();
stub = sinon.stub(soap,'callSoap');
});
it("test a", ()=>{
let fakeout = {
resp : "tada!"
}
stub.resolves(fakeout);
myclass.myMethod(1).then(result =>{
console.log(result) //<----- this is the fakeout
}
)
});
});