Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!