Skip to content

test: expand React subscribe test coverage#3442

Merged
dbritto-dev merged 2 commits into
pmndrs:mainfrom
mahmoodhamdi:test/expand-react-subscribe-tests
Mar 30, 2026
Merged

test: expand React subscribe test coverage#3442
dbritto-dev merged 2 commits into
pmndrs:mainfrom
mahmoodhamdi:test/expand-react-subscribe-tests

Conversation

@mahmoodhamdi

Copy link
Copy Markdown
Contributor

Summary

The React-level tests/subscribe.test.tsx only had a single test that checked typeof subscribe === 'function'. Meanwhile, the vanilla counterpart (tests/vanilla/subscribe.test.tsx) has 9 comprehensive tests.

This expands the React subscribe tests to cover actual subscription behavior through the create() API.

Tests Added

  • State identity check (same reference → no notification)
  • State change notification with previous/current state
  • subscribeWithSelector: slice-based subscriptions
  • subscribeWithSelector: custom equality functions
  • subscribeWithSelector: fireImmediately option
  • Unsubscription
  • Multiple subscribers
  • Selective unsubscription (one listener removed, others remain)

Goes from 1 test → 12 tests for React subscribe behavior.

Verification

  • All 207 tests pass
  • TypeScript check clean
  • ESLint clean
  • Prettier clean

The React-level subscribe.test.tsx only had a single test checking that
subscribe is a function. This adds comprehensive tests mirroring the
vanilla subscribe tests, covering state change notifications,
subscribeWithSelector integration, equality functions, unsubscription,
fireImmediately, and multiple subscriber behavior.
@vercel

vercel Bot commented Mar 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zustand-demo Ready Ready Preview, Comment Mar 30, 2026 6:40pm

Request Review

@codesandbox-ci

codesandbox-ci Bot commented Mar 29, 2026

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new

pkg-pr-new Bot commented Mar 30, 2026

Copy link
Copy Markdown

commit: 750f869

@dbritto-dev dbritto-dev merged commit 6330044 into pmndrs:main Mar 30, 2026
33 checks passed
@dbritto-dev

Copy link
Copy Markdown
Collaborator

thanks for your contribution

Comment thread tests/subscribe.test.tsx
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { create } from 'zustand'
import { subscribeWithSelector } from 'zustand/middleware'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, we will probably drop this in the next major version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants