BigTest add way to assert thrown exception
For now there is no way to test a specific thrown Error message. As example if we have this test where calendar day restriction is limited and we try to select disabled day.
test
.step(renderCalendar({ maxDate: new Date("2014-08-18") }))
.step(calendar.setDay(20))
.assertion(/* ??? */)
The calendar should throw new Error(Can't select ${day} day because it's disabled);
Could we say
test
.step(renderCalendar({ maxDate: new Date("2014-08-18") }))
.assertion(Fails(calendar.setDay(20)))
@cowboyd What about?
test
.step(renderCalendar({ maxDate: new Date("2014-08-18") }))
.exception(calendar.setDay(20))
// Or
.exception('With error message', calendar.setDay(20))
The reason is setDay is an action and it could produce side-effects
Another approach is don't fail on any step exception, just collect the error and check it in the assertion step, like this:
test
.step(renderCalendar({ maxDate: new Date("2014-08-18") }))
.step(calendar.setDay(20))
.assertion(Fails('With error message'))
Hmmm...
I think option two is more doable today:
test
.step(renderCalendar({ maxDate: new Date("2014-08-18") }))
.step("try to set calendar day", async () => {
try {
await calendar.setDay(20);
return { error: null };
} catch (error) {
return { error };
}
})
.assertion(({ error }) => assert(error != null error.mesage == 'with error message'))
I transferred this to bigtest, since it is more relevant to bigtest than interactors.