0
나는 sharp을 조롱하기 위해 노력하고있어 나는이 있습니다농담 조롱 - 어떻게이 모듈을 조롱합니까?
// /__mocks__/sharp.js
const Sharp = jest.genMockFromModule('sharp')
Sharp.prototype.jpeg = function (options) { return this }
Sharp.prototype.trim = function (options) { return this }
Sharp.prototype.normalise = function (bln) { return this }
Sharp.prototype.background = function (colour) { return this }
Sharp.prototype.embed = function() { return this }
Sharp.prototype.clone = function() { return this }
Sharp.prototype.resize = function (width, height) { return this }
Sharp.prototype.toBuffer = function() {
return Buffer.from('')
}
export default Sharp
I import sharp from 'sharp'
및 console.log(sharp)
내가 얻을 때 :
function Sharp() {return mockConstructor.apply(this,arguments);}
잘 보인다
, 내 모의 모듈이 아닌 실제를 찾았다 기준 치수. 내가 조롱 모듈을 사용하여, 테스트 코드에서sharp()
를 호출 할 때 그것은 오히려
instanceof sharp
보다 값이
undefined
입니다이다, 그러나
const sharpImage = sharp(input, options).jpeg(options).trim()
const myImageBuff = await sharpImage.toBuffer()
:
는이 같은 sharp
를 사용합니다.
const Sharp = jest.genMockFromModule('sharp')
을 function Sharp (input, options) { return this }
으로 바꾸려고 시도했지만 아무런 차이가 없습니다.
내가 뭘 잘못하고 있니?.