Testing Contextual Slot Specs

In this lesson, we'll see what Contextual Slot Specs are and how to test them.

We'll cover the following

What is the Need?

We’ve tested how and where the slots render, and that’s probably all we need. However, it doesn’t end there. If you pass component instances as slots, just as we’re doing in the default slot with Message, you can test the functionality related to it.

Be careful of what you test here; this is probably something you don’t need to do in most cases since the functional tests of a component should belong to that component test. When talking about testing slots functionality, we test how a slot must behave in the context of the component where that slot is used, and that’s not very common. Normally we just pass the slot and forget about it. So don’t get too stuck to the following example: its only purpose is to demonstrate how the tool works.

Let’s say that, for whatever reason, in the context of the MessageList component, all the Message components must have a length higher than 5. We can test that like:

Get hands-on with 1200+ tech skills courses.