Transcript
00:00 Crafting custom domain-specific utilities is a great way to elevate your test setup and turn your tests into a composition of declarative steps followed by assertions. As always, there are multiple ways to approach utilities in tests. For example, you can import the things you need directly in your test suits or go a different route
00:18 and introduce what is called a fixture. VTest's approach to fixtures is heavily inspired by Playwright. When you can get this first argument, your test callback, often referred to as test context, and if you destructure it, you can gain access to your custom fixtures, but also to built-in utilities provided by VTest, like for example an expect function
00:36 or the onTestFailed callback to react to when this test case fails. But you can push this even further. You can extend the default test context and imbue it with custom fixtures specific to the application that you're testing. And I've got a great use case for you to learn how. In our application, we have this utility called getTotalPrice
00:54 that accepts a cart object and returns a number. That number stands for the total price of all the items in the cart, respecting the individual item price multiplied by the quantity of how many of those items you have in cart. So basically, to test this function, you need to provide it with
01:10 a cart argument, this cart object. You can of course create this object in tests next to each individual scenario, but you can also use a fixture to help you model different cart states and move that cart dependency out of the test cases. And that is exactly your task for this
01:25 exercise. Follow the instructions to implement your own createMockCart fixture, and also use the library Faker.js to help you populate it with random data. Then once you're done, make sure to finish the test cases so you're able to test different scenarios when calculating the total price of your cart. Give it your best, and see you once you're done.