Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigTest add way to assert thrown exception #1036

Open
wKich opened this issue Apr 20, 2021 · 4 comments
Open

BigTest add way to assert thrown exception #1036

wKich opened this issue Apr 20, 2021 · 4 comments

Comments

@wKich
Copy link
Member

wKich commented Apr 20, 2021

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

@cowboyd
Copy link
Member

cowboyd commented Apr 21, 2021

Could we say

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

@wKich
Copy link
Member Author

wKich commented Apr 23, 2021

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

@cowboyd
Copy link
Member

cowboyd commented Apr 23, 2021

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

@cherewaty cherewaty transferred this issue from thefrontside/material-ui-interactors Sep 13, 2021
@jnicklas jnicklas transferred this issue from thefrontside/interactors Oct 26, 2021
@jnicklas
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants