I'm writing tests for a library that uses postcss. One of my test verifies that CssSyntaxError is thrown.
With [email protected] my test now fails with Promise rejected with exception that is not an error: CssSyntaxError {...}.
I think postcss should throw an Error that actually extends Error, however this type of situation might happens within many library and that make it harder to test code that uses those with [email protected].
Is there a way to tell t.throws and t.throwsAsync to allow to test function that throws object that are not Errors? If not should it be included at least as an option?
Duplicate of #1841
Any workaround to suggest when your code depends on a library on which you don't have control that throws non Error object?
I think postcss should throw an Error that actually extends Error, however this type of situation might happens within many library and that make it harder to test code that uses those with [email protected].
So the end-result is that AVA encourages postcss to make CssSyntaxError an actual Error. That sounds like a win to me.
1841 was closed, so I opened this one. Does it means this won't be addressed?
We can continue to discuss it here. If we decide that it's worth doing something about it, we'll reopen this issue.
Any workaround to suggest when your code depends on a library on which you don't have control that throws non Error object?
Fix the library? I realize it's not always that simple, but I also don't want to enable bad patterns in AVA and complicate the assertion method and typing definitions for such an edge-case anti-pattern that can actually be fixed in the offending library.
// @ai
@pvdlg show your test
That makes sense and in the case of a popular and well maintained library like postcss it's definitely possible to fix. However it's not always the case. So it might worth it to includes an option in ava to avoid "punishing" ava user for something they are not really responsible for.
@ai this is this test: https://github.com/pvdlg/karma-postcss-preprocessor/blob/a6ce488420ed3e7a414cb27a7687039a384b4760/test/unit.test.js#L153
Let me know if you want a reduced test case.
We removed Error from CssSyntaxError parents because of Babel error. I can try to add it back.
Released in 7.0.7
Thanks a lot!