我正在使用jest&进行一些集成测试nock来测试Axios 拦截器链接。
在其中一个中,我期望收到一个Blob实例
,根据此链接,我应该能够使用它的text()方法。
我的问题是:为什么这个方法没有定义?(在我的测试中)
这是(简化的)代码:
// interceptors.js
const useBlobTextProperty = async (response) => {
const { data: myBlob } = response
console.log(myBlob.toString()) // Prints "[object Blob]"
response.rawText = await myBlob.text() // TypeError: myBlob.text is not a function
return response
}
Run Code Online (Sandbox Code Playgroud)
// foo.test.js
import axios from 'axios'
import httpAdapter from 'axios/lib/adapters/http'
import nock from 'nock'
const testAxios = axios.create({
responseEncoding: 'utf8',
responseType: 'blob',
})
testAxios.interceptors.response.use(useBlobTextProperty, null) …Run Code Online (Sandbox Code Playgroud)