Мне интересно, почему моя заглушка игнорируется.
Допустим, у меня есть файл с именем myfile.ts
, который экспортирует два асинхронных метода. A
и B
.
import { sendResult } from '../index'
export async A(): Promise<string[]> {
// making an async api call
const result = await apiCall()
// do sync treatement on result then send it back
...
return value
}
export async B(): Promise<void> {
// Calling A()
const aResult = await A()
// do some sync treatement and call a method from an other module than
// returns a Promise<void>
...
sendResult()
}
Мне нужно провести модульное тестирование моего B
метода и заглушки A
и sendResult
Мой testFile.ts выглядит как
import { sandbox } from 'sinon'
import * as AB from './modules/ab'
import * as INDX from './index'
const testSandbox = sandbox.create()
describe('my tests', function () {
beforeEach(() => {
testSandbox.stub(INDX, 'sendResult').resolves()
testSandbox.stub(AB, 'A').resolves([])
})
afterEach(() => {
testSandbox.restore()
})
it('should pass but it is not', async function (done) {
await AB.B()
const sendResultStub = UL.sendResult as SinonStub
assert.calledOnce(sendResultStub)
done()
})
})
Я не понимаю, почему sendResult
хорошо заглушен, а A
- нет. Что мне не хватает?
Спасибо, ребята, заранее!
Бастьен