Testing the useCompletion hook

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Table of Contents

This lesson preview is part of the Responsive LLM Applications with Server-Sent Events course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Responsive LLM Applications with Server-Sent Events, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Responsive LLM Applications with Server-Sent Events
  • [00:00 - 00:53] Welcome back! In this lesson, we will learn how to test our use completion "OOC". Testing "OOC" is a fairly standard task and there are many very useful libraries that exist to make our life simpler. We will use "Vit" - "Vit Test" and the "React Testing Library". Now, here you can see the documentation of "Vit Test" with a complex explanation of how to install it and how to use it. Here you have "React Testing Library" which is a library built by CanCidots and you can find on the blog of CanCidots explanation and detail are how you're supposed to test a custom React OOC. What's important to remember is that "OOCs" are meant to be run inside a component so to run our OOC we need to build a test component just for the test . So here a setup function as you can see that we will use to run the "Vioc".

    [00:54 - 03:10] Another remark to setup everything with "Type Script" "Vit Test" "React Testing Library " and so on. The config can be a bit tricky so if you want to take some problem go look up the "Cloud" section there are an example of the successful setups and as you can see there are some questions stuck overflow and github and read it because they can be some nasty bugs. Now, so we are testing to that "OOCs" but how do we handle the streaming part? We already have done a lot of work. What was in it was a mock stream and we already did show in the previous lesson how to build this mock stream so now let's use it and here let's see an example of a test. I'm building a mock stream I'm setting up my test component here and here you see I'm using dependency and junction to pass a use chart query rendering my mock reader. Now we make our action for the test and our channel is to unqueue a server-cent event in our stream and here we are sending a chunk a little world and now we can check whether or not our use completion hook indeed returns a little world. Now there are several things to make sure we get right. The first we must await the action because our old workflow is a synchronous and if we are not careful we are going to get some action made after the test has finished run. That will show up as an "Not wrapped in act" error in new shell. So if you are seeing this error it means that somewhere you forgot to narrow it. And secondly make sure to clean up everything and you're too close or controller before the end. So that's an example of the "Rison Per Test" with an "Arron Act Assert Structure" and here on our test system we are sending two chunks and we are making sure that the hook indeed returns "retext" as a concatenation. So that was all for the testing part and we have finished the front end and so that's the end of this module and in the next module we will start building the backend. See you soon!