◉GEMINI LABJP
●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…
Articles/Dev Tools
⟐ Dev Tools/2026-04-29Advanced

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

Vitest patterns for TypeScript code that calls Gemini — SDK mocks, Function Calling and streaming tests, dropping to MSW, and a one-call nightly smoke test.

gemini-api286vitesttypescript16testing3mockfunction-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
✦MSW handlers that survive an SDK response-shape change without rewriting every test
✦A single nightly live call that catches model deprecation and auth expiry, nothing else
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

◈ 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.
⟐ Dev Tools2026-09-03
When Gemini Let Me Upload Several Code Files at Once, I Stopped Selecting by Folder
Once you can hand Gemini a slice of a repository, the hard part moves from pasting to choosing. I measured the dependency graph of my own Next.js repo, found that folder-based selection caught zero callers, and wrote down the selection routine I use now.
⟐ Dev Tools2026-08-21
Why My Length Limit Only Failed on the English Notifications, and the Width-Based Fit That Replaced It
I had Gemini write push notifications in Japanese and English, and only the English ones came out truncated on real devices. The culprit was measuring length in characters. Here are the measured widths and the post-generation fitting code that fixed it.