0
jestを使用して模擬しようとしています。以下は試してみたい疑似コードです。 jestである。冗談を嘲笑いにいくつかの考えを投げてください。私はsinon.stub()
に類似したものを探していて、resolve()
を使って簡単に解決できます。ジョイントを使って非同期モックが動作しない、より良い方法や簡単な方法がありますか?
class ExampleService {
static get() {
agent.get("/examples")
}
}
ExampleStore:
class ExampleStore {
const examples = []
getExamples() {
ExperimentService.get().then((result) = > {
this.examples = result
})
}
}
のテストケース:
describe("ExampleStore",() = > {
it("getExamples",() = > {
data = [{
test: "test"
}]
ExperimentService.get = jest.fn(() = > {
return new Promise((resolve) = > {
process.nextTick(resolve(data)
}) ExampleStore.getExamples() expect(ExampleStore.examples).toBe(data)
}
})
})