Unit testing Auth0 Actions

We are very excited about the release of Actions, which provide an export that can be used for testing purposes, unlike Rules.

Since the Actions typically do not return something like a callback, what are the recommended strategies for unit testing these functions? I have not found any documentation around testing Auth0 code. This also applies to database connection scripts, although without any exports, I am unsure of how to go about testing those at all. Any ideas are appreciated!

Thank you!

Hey there!

Let me reach out to the team to find out more about it!

Hey there! Unfortunately as of now we still don’t have any content around it but I was asked by the team to ask you to file a feature request for that using our Feedback category here:

I voted for the feature Include unit-testing examples / best practices in documentation

It’s unfortunate to hear this is treated as a feature request, when it’s really just basic documentation for using the product. I should not need to request a feature to know how to use something. Surely the development team is creating features with testing capabilities in mind, it would be great to even share the recommended strategies.

The team indeed made some design decisions around the architecture used in Actions so that they could eventually offer a nice DX for customers to unit test Actions in isolation but the guide is not live yet.

Further to this it would be extremely useful if auth0 released a package to help with testing actions. As it is we have to create quite extensive mocks for the event & api arguments, it’s quite feasible that our tests may pass but because we have mocked out the api interface wrongly it will not work in auth0.

Thanks for providing that feedback! Can you file it as a feature request using our Feedback category here:

Hi Konrad,

Any update on the Actions unit test guide that is not live yet?

Checking for any updates. Thank you!

Hi @ben_wozniak,

Konrad is out of the office, but will be back next week and should be able to follow up on this one. Just wanted to let you know!

Hey there!

I reached out to the team and they said that they captured it in their opportunity backlog. As soon as they release that I will let you know!

1 Like

Hey, @konrad.sopala. Any update on this?

1 Like

Hi @ben_wozniak! Giving my two cents, I think you can unit test your Action mocking all the contracts. However, I understand this one is not suitable for some critical scenarios. So, I recently did a small project showing how to test your Action when the scenario is ready on Auth0 platform. As it is right now, the only drawback is that you must create your scenario by hand before the test execution. This can automatically be done through the Management API, though.

I don’t know if we’re going to use Auth0 in a project I’m responsible for. Still, if that is the case, we intend to create a fully automated test for Actions using the following:

  • Management API: We can make the test case and evaluate the result after a flow is completed using it.
  • Functional Testing: Responsible for executing the flow as the user would do.
  • Jest

I wrote a blog post explaining how to do that with Cognito. The code can be checked here. Maybe it can come in handy for you.

Hey there!

Unfortunately it’s not there yet. Will really let you know once it’s there :slight_smile: Thank you for patience!

Just wanted to let everyone know that we just published a more complete guide on testing Actions. Please take a look and let us know in this thread if there is anything missing that you’d like to be able to do.


Wooohooo thanks for sharing that with the rest of community!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.