Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Mock getSignedUrl from Google Storage File using Jest

I have a piece of code that make use of getSignedUrl

onst [url] = await blob.getSignedUrl({ action: 'read', expires: Date.now() + 60 * 1000, contentType: mimetype })

Unfortunately, firebase emulator cannot sign the URL, my workaround is to mock the return value of blob.getSignedUrl

As following

import { File } from '@google-cloud/storage'

jest.mock('File', () => ({
  ...jest.requireActual('@google-cloud/storage'),
  getSignedUrl: jest.fn().mockReturnValue({ url: 'http://' }),
}))

Although this has no effect. How can I mock getSignedUrl function?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

jest.mock takes the module name (or the path) as parameter.

I guess what you wanted to do is to use a spy :

import { File } from '@google-cloud/storage'

const spy = jest.spyOn(File.prototype, 'getSignedUrl')
spy.mockReturnValue({ url: 'http://' })

// if you dont need to keep spy you can do it in one line :
// jest.spyOn(File.prototype, 'getSignedUrl').mockReturnValue({ url: 'http://' })
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda