Use BlockEdit for block rendering unit tests #29442
Labels
Mobile App - i.e. Android or iOS
Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
[Status] In Progress
Tracking issues with work in progress
[Type] Task
Issues or PRs that have been broken down into an individual action to take
What problem does this address?
Currently the unit tests related to rendering blocks are using the edit component of the different blocks. However the blocks are rendered in the editor through the
BlockEdit
component which includes a context with different properties likeclientID
that could be required by other logic from the blocks.In fact, I realised when testing the changes that will introduce this PR, that rendering blocks without a
clientId
produce errors when running the unit tests, in this case the selectorisBlockSelected
which is heavily used in blocks returnstrue
when theclientId
isundefined
.What is your proposed solution?
My solution here is to add extra logic to the unit tests that renders blocks, first we should register the block as the editor does and then create a function that returns the
BlockEdit
component that will render the block we want to test.Here is an example:
As you can see, instead of rendering the Edit component of the block, we use the
BlockEdit
component by passing the block's name through thename
prop and a defaultclientId
.The text was updated successfully, but these errors were encountered: