Skip to content

add type checking to asyncAct args #469

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

Conversation

ely-alamillo
Copy link

@ely-alamillo ely-alamillo commented Aug 29, 2019

What:
This PR fixes issue: #442 by adding type checking for args used in asyncAct function.

Why:
Current implementation assumes console.erorr was always called with a string even though it could be called with other types.

How:
Wrapped execution of code in a type check if statement to ensure operations are done only on string types.

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests
  • Typescript definitions updated N/A
  • Ready to be merged

@ely-alamillo ely-alamillo changed the title add type checking to asyncAct args closes #442 Aug 29, 2019
@ely-alamillo ely-alamillo changed the title closes #442 add type checking to asyncAct args Aug 29, 2019
@kentcdodds
Copy link
Member

Thanks. What happens if console.error is called with a non-string? I believe that currently this will result in the originalConsoleError not getting called.

@ely-alamillo
Copy link
Author

That is correct. I can move the else out of the if block to have it run whenever there is no string.

test('async act handles values that are not strings', async () => {
try {
await asyncAct(() => {
throw new Error({error: 'test error'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to do a console.error({ message: 'some message' } insteadof throwing it, to mimic the problem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the test to not throw error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct 👍

but you had to change the assertion of another test, which is an indication of a wrong implementation (you are still not calling the original console.error)

check this implementation for inpiration :-):
rvdkooy@9020b83

@kentcdodds can you have a look if we're on the right track with this?

@@ -32,18 +32,15 @@ test('async act works even when the act is an old one', async () => {
console.error('sigil')
})
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"sigil",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this log is no longer happening. Could you fix your changes so you don't have to change this snapshot?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed implementation to revert back to this snapshot.

) === 0
) {
// no-op
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else {
originalConsoleError.apply(console, args)
}

I think that should do it.

@kentcdodds
Copy link
Member

It looks like this is still unresolved... That snapshot should not change at all.

@rvdkooy
Copy link
Contributor

rvdkooy commented Sep 3, 2019

@ely-alamillo check this PR for the solution:
#476
(you can take the code if you want)

@kentcdodds
Copy link
Member

Thank you @rvdkooy. I've merged your PR.

Thank you @ely-alamillo for doing the initial work here. Even though we weren't able to merge your PR, I'm still happy for your efforts in contributing to the project!

@kentcdodds
Copy link
Member

@all-contributors please add @ely-alamillo for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @ely-alamillo! 🎉

@kentcdodds kentcdodds closed this Sep 3, 2019
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

Successfully merging this pull request may close these issues.

3 participants