bigtest icon indicating copy to clipboard operation
bigtest copied to clipboard

BigTest add way to assert thrown exception

Open wKich opened this issue 4 years ago • 4 comments

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);

wKich avatar Apr 20 '21 04:04 wKich

Could we say

test
  .step(renderCalendar({ maxDate: new Date("2014-08-18") }))
  .assertion(Fails(calendar.setDay(20)))

cowboyd avatar Apr 21 '21 08:04 cowboyd

@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'))

wKich avatar Apr 23 '21 10:04 wKich

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'))  

cowboyd avatar Apr 23 '21 12:04 cowboyd

I transferred this to bigtest, since it is more relevant to bigtest than interactors.

jnicklas avatar Oct 26 '21 14:10 jnicklas