# Unit testing Auth0 Actions

**URL:** <https://community.auth0.com/t/unit-testing-auth0-actions/67246>\
**Category:** Get Help\
**Tags:** unit-testing, actions\
**Created:** [August 2, 2021, 4:10pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246 "2021-08-02T16:10:02Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben\_wozniak](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ben_wozniak/32/20554_2.png) [@ben\_wozniak](https://community.auth0.com/u/ben_wozniak)\
**Post date:** [August 2, 2021, 4:10pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/1 "2021-08-02T16:10:02Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 3, 2021, 11:49am UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/2 "2021-08-03T11:49:42Z")

</div>

Hey there!

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

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 12, 2021, 12:24pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/4 "2021-08-12T12:24:11Z")

</div>

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:

> **[Feedback](https://community.auth0.com/c/feedback/95)**
>
> Submit and vote on product feedback and feature requests.

---

<div class="post-metadata">

**Author:** ![ben\_wozniak](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ben_wozniak/32/20554_2.png) [@ben\_wozniak](https://community.auth0.com/u/ben_wozniak)\
**Post date:** [August 12, 2021, 12:59pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/5 "2021-08-12T12:59:01Z")

</div>

I voted for the feature [Include unit-testing examples / best practices in documentation](https://community.auth0.com/t/include-unit-testing-examples-best-practices-in-documentation/61799)

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.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 12, 2021, 2:25pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/8 "2021-08-12T14:25:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jack.macdonald](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.macdonald/32/12764_2.png) [@jack.macdonald](https://community.auth0.com/u/jack.macdonald)\
**Post date:** [September 2, 2021, 2:28pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/9 "2021-09-02T14:28:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [September 2, 2021, 2:38pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/10 "2021-09-02T14:38:25Z")

</div>

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

> **[Feedback](https://community.auth0.com/c/feedback/95)**
>
> Submit and vote on product feedback and feature requests.

---

<div class="post-metadata">

**Author:** ![ben\_wozniak](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ben_wozniak/32/20554_2.png) [@ben\_wozniak](https://community.auth0.com/u/ben_wozniak)\
**Post date:** [September 3, 2021, 1:25pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/11 "2021-09-03T13:25:16Z")

</div>

Hi Konrad,

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

---

<div class="post-metadata">

**Author:** ![ben\_wozniak](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ben_wozniak/32/20554_2.png) [@ben\_wozniak](https://community.auth0.com/u/ben_wozniak)\
**Post date:** [September 15, 2021, 4:22pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/12 "2021-09-15T16:22:33Z")

</div>

Checking for any updates. Thank you!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 15, 2021, 8:54pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/13 "2021-09-15T20:54:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [September 24, 2021, 10:26am UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/14 "2021-09-24T10:26:57Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![zanebclark](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/zanebclark/32/32969_2.png) [@zanebclark](https://community.auth0.com/u/zanebclark)\
**Post date:** [November 12, 2021, 5:28pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/15 "2021-11-12T17:28:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![willianantunes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/willianantunes/32/32398_2.png) [@willianantunes](https://community.auth0.com/u/willianantunes)\
**Post date:** [November 12, 2021, 6:18pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/16 "2021-11-12T18:18:53Z")

</div>

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](https://github.com/willianantunes/auth0-custom-universal-login/blob/99f4796a645a726a93b57981261a6125ba9de332/tests/src/actions/action-post-user-registration-account-linking.spec.test.js#L19-L71). 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](https://www.willianantunes.com/blog/2021/11/sso-with-cognito-through-the-authorization-code-grant-type/). The code can be checked [here](https://github.com/willianantunes/tutorials/tree/master/2021/11/sso-cognito-authorization-code-grant-type). Maybe it can come in handy for you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 15, 2021, 8:13am UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/17 "2021-11-15T08:13:36Z")

</div>

Hey there!

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

---

<div class="post-metadata">

**Author:** ![josh.cunningham](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josh.cunningham/32/16289_2.png) [@josh.cunningham](https://community.auth0.com/u/josh.cunningham)\
**Post date:** [January 31, 2022, 6:54pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/18 "2022-01-31T18:54:55Z")

</div>

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.

> **[Test Actions](https://auth0.com/docs/customize/actions/test-actions)**
>
> Learn how to test and debug Auth0 Actions

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [February 3, 2022, 1:44pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/19 "2022-02-03T13:44:18Z")

</div>

Wooohooo thanks for sharing that with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 18, 2022, 1:45pm UTC](https://community.auth0.com/t/unit-testing-auth0-actions/67246/20 "2022-02-18T13:45:03Z")

</div>

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