perhaps try rewriting it in a way that expect can catch the error?