GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
Articles/Dev Tools
Dev Tools/2026-04-29Advanced

Testing Gemini API with Vitest — Mock Patterns and Function Calling Verification for TypeScript Projects

Practical patterns for testing TypeScript code that calls the Gemini API, using Vitest. Covers SDK mocking, Function Calling verification, and streaming response tests, drawn from a setup I run in personal projects.

gemini-api277vitesttypescript15testing2mockfunction-calling20

Premium Article

I changed one line of a prompt and production responses quietly broke

This actually happened in one of my side projects. I tweaked the system instruction on a review-summarization function from "three bullet points" to "three points by importance," and silently lost the closing sentence of every summary for several days before I noticed. There were plenty of regression-testing articles for Pytest, but surprisingly few examples of doing the same on the TypeScript side. I ended up writing the harness on the spot.

This article is a cleanup of that harness. If you're using Vitest with the @google/generative-ai SDK, here's what I've found works for keeping Gemini-calling code easy to refactor: the mocking shape, the Function Calling tests, the streaming tests, in roughly the order I'd build them up.

I'm assuming you've been writing TypeScript with Gemini for a few weeks to a few months and want to lay down testing foundations before things grow further. The patterns are equally usable in team settings as a starting point.

Why Vitest, from a solo developer's perspective

Jest can do all of this too. I still reach for Vitest first in TypeScript-and-ESM projects, for three reasons.

First, ESM support is uncomplicated. Modern SDKs like @google/generative-ai are ESM-first, and Jest tends to need careful transform configuration to keep up. Vitest mostly just runs. Second, if your project already uses Vite (Astro, SvelteKit, Remix), Vitest shares the configuration. Third, Vitest starts up quickly. Tests that touch Gemini are slower than pure-logic tests, so a leaner runner gives you back a non-trivial amount of time over a working day.

There are good reasons to keep Jest. React Native projects, or any codebase with a lot of Jest-specific tooling, aren't worth migrating just for this. The patterns below port to Jest with minimal edits — substitute jest.fn and jest.mock and you're mostly done.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Test designs that fire 429/503 on purpose to pin retry ceilings and fail-fast paths
Skipping exponential backoff with vi.useFakeTimers for zero real-time waits
A measured setup running 41 cases in 0.9s with zero live API calls, saving 10k+ calls a month
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Dev Tools2026-04-03
Next.js 15 App Router × Gemini API: The Complete Full-Stack
Build production-grade full-stack AI applications with Next.js 15 App Router and the Gemini API. Covers Server Actions, Streaming, RAG pipelines, authentication, rate limiting, and deployment.
Dev Tools2026-03-31
Building Custom MCP Servers for Gemini API — Extending AI Agents with TypeScript
Learn how to build custom Model Context Protocol (MCP) servers in TypeScript and integrate them with Gemini API. Covers architecture, authentication, error handling, and production deployment patterns.
API / SDK2026-05-09
Build a Voice + Screen-Share AI Pair Programmer with the Gemini Live API in TypeScript
A practical playbook for wiring the Gemini Live API to getDisplayMedia and a microphone to build an over-the-shoulder AI pair programmer in TypeScript, with cost controls and the gotchas I hit in production.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →