---
title: "Discussion on \"NextJs Testing: window.matchMedia is not a function in use-mobile hook\" | Hashnode"
description: "Discussion on \"NextJs Testing: window.matchMedia is not a function in use-mobile hook\". While writing tests for my Next.js app using Vitest and React Testing Library, I ran into an annoying error that looked like this:\nTypeError: window.matchMedia is not a function\n ❯ hooks/use-mobile.ts:12:24\n\nThe error was pointing to this line inside..."
url: "https://hashnode.com/posts/nextjs-testing-windowmatchmedia-is-not-a-function-in-use-mobile-hook/684c0412fa630af840ab3a38"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [NextJs Testing: window.matchMedia is not a function in use-mobile hook](https://abdqaadir.hashnode.dev/nextjs-testing-windowmatchmedia-is-not-a-function-in-use-mobile-hook?utm_source=hashnode&utm_medium=feed)

While writing tests for my Next.js app using Vitest and React Testing Library, I ran into an annoying error that looked like this: TypeError: window.matchMedia is not a function ❯ hooks/use-mobile.ts:12:24 The error was pointing to this line inside...

Jun 13, 2025 · 2 min read · abdqaadir.hashnode.dev  
Read the article

-   [#testing-library](https://hashnode.com/tag/testing-library)
-   [#testing](https://hashnode.com/tag/testing)
-   [#vitest](https://hashnode.com/tag/vitest)
-   [#nextjs](https://hashnode.com/tag/nextjs)

## Written by

[Lateef Quadri Olayinka](https://hashnode.com/@AbdQaadir)

@AbdQaadir · Akure, Nigeria

  
[View profile](https://hashnode.com/@AbdQaadir)

Front End Developer

I am AbdQaadir by name. A Nigeria based Front End Developer. I'm interested in Software Engineering and Cyber Security.

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
