I found it confusing to read. I was reading L171 and wondering to myself "why wouldn't expected by defined?" You have an implicit invariant that either error or expected will be defined. I think splitting it up would make that invariant explicit and therefore make the code more readable.

But I also believe you if you thought it was clearer this way.

Is there a reason to define the asserts as a function outside of the test case? Why not just inline the conditional?