Stream: beginners

Topic: ✔ `expect` is wonderful!


view this post on Zulip Jasper Woudenberg (Mar 09 2024 at 21:07):

This is not a question, something that delighted me when I ran into it today and I wanted to share a thank you: I love the way expect will print the values of variable assignments when a test failed.

At first I was briefly confused when I didn't get a diff for a failed test that did a callFun 4 == [1,2,3]-style comparison. I checked the documentation, saw the note about assigning values to variables to get them logged in test failures and thought it a bit weird. Then it clicked: this means it's super easy to add any information I want to test failures! I love it, such a nice tool for designing tests that fail with nice errors!

view this post on Zulip Notification Bot (Mar 09 2024 at 21:07):

Jasper Woudenberg has marked this topic as resolved.

view this post on Zulip Jonas Schell (Mar 10 2024 at 09:44):

@Jasper Woudenberg your command captured my experience too. I wonder if we could reduce the confusion time by changing the documentation. For example, when I first read this part of the documentation:

If a test fails, it will not show the actual value that differs from the expected value. To show the actual value, you can write the expect like this:

My initial reaction was "Why? That seems unexpected and unergonomic, forcing me to make a one-liner into two lines". Perhaps highlighting the benefits and/or giving some context as to why it is done this way might help overcome the initial confusion or rejection.

view this post on Zulip Anton (Mar 12 2024 at 10:53):

... why it is done this way ...

I don't remember it clearly but I think it was just the easiest way to implement this type of debug printing.

view this post on Zulip Richard Feldman (Mar 12 2024 at 11:52):

yeah exactly - I'd like to expand it to print the answers to all the function calls in the final expression, but that's a bigger project :big_smile:

view this post on Zulip Richard Feldman (Mar 12 2024 at 11:53):

that said, it's not a huge project; if anyone wants to work on it lmk and I can give the necessary context!

view this post on Zulip Anton (Mar 12 2024 at 12:26):

For tracking; this is issue #4633. I'll include a short note in the tutorial as well.


Last updated: Jul 06 2025 at 12:14 UTC