Skip to content

Conversation

@matthewlipski
Copy link
Collaborator

Summary

This PR adds unit tests for editorHasBlockWithType.

The code for editorHasBlockWithType has also been changed slightly - when checking for a block with a given propSchema and values, the values can be an unordered subset of the ones in the schema. Previously, the 2 arrays had to be identical in order for the type guard to return true.

Rationale

Needed for #2096 and useful in general.

Changes

See above.

Impact

N/A

Testing

See above.

Screenshots/Video

N/A

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

@vercel
Copy link

vercel bot commented Oct 14, 2025

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

Project Deployment Preview Updated (UTC)
blocknote Ready Ready Preview Oct 16, 2025 11:19am
blocknote-website Ready Ready Preview Oct 16, 2025 11:19am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 14, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@2103

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@2103

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@2103

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@2103

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@2103

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@2103

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@2103

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@2103

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@2103

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@2103

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@2103

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@2103

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@2103

commit: eca2839

Copy link
Contributor

@nperez0111 nperez0111 left a comment

Choose a reason for hiding this comment

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

Easy enough, just a nice to have case to add

@nperez0111 nperez0111 changed the title feat: Unit tests for block type guards test: unit tests for block type guards Oct 16, 2025
@matthewlipski
Copy link
Collaborator Author

Also @YousefED we talked on call yesterday about whether to put additional tests in the tests directory or with the files that they're actually testing. Should we have the same discussion with @nperez0111 before merging this or is that for another time?

Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

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

approved.

do the fixes to the source file mean there were bugs in the implementation btw?

(created separate ticket for testing discussion)

@matthewlipski
Copy link
Collaborator Author

Yeah the !== undefined additions are to fix bugs, since things like empty strings set as default props would cause issues. Not sure if other change with values counts as a fix or not, it just makes it easier e.g. if you want to see if the textAlignment prop allows for "justify" alignment. You'd previously have to check with:

editorHasBlockWithType(editor, "paragraph", {
  textAlignment: {
    default: "left",
    values: ["left", "center", "right", "justify"]
  }
})

and now it's just:

editorHasBlockWithType(editor, "paragraph", {
  textAlignment: {
    default: "left",
    values: ["justify"]
  }
})

@YousefED
Copy link
Collaborator

YousefED commented Oct 17, 2025 via email

@matthewlipski matthewlipski merged commit e6d3027 into main Oct 17, 2025
8 checks passed
@matthewlipski matthewlipski deleted the block-type-guards-tests branch October 17, 2025 11:54
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