# Unit Testing

**URL:** <https://forums.fusetools.com/t/unit-testing/1254>\
**Category:** How-to Discussions\
**Created:** [May 29, 2017, 7:21pm UTC](https://forums.fusetools.com/t/unit-testing/1254 "2017-05-29T19:21:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filipe\_Almeida](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Filipe\_Almeida](https://forums.fusetools.com/u/Filipe_Almeida)\
**Post date:** [May 29, 2017, 7:21pm UTC](https://forums.fusetools.com/t/unit-testing/1254/1 "2017-05-29T19:21:12Z")

</div>

Hello, i’m trying to configure a unit testing tool; as it runs node, it complains for every module i required.  
Things like Promise and Observables must be hidden/shimmed which makes the code a mess. (and defeats the purpose)

Is there any clean way to run tests including those classes?

---

<div class="post-metadata">

**Author:** ![Sebastian\_Reinhard](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/sebastian_reinhard/32/513_2.png) [@Sebastian\_Reinhard](https://forums.fusetools.com/u/Sebastian_Reinhard)\
**Post date:** [May 30, 2017, 4:36pm UTC](https://forums.fusetools.com/t/unit-testing/1254/2 "2017-05-30T16:36:35Z")

</div>

Hi! Fuse has support for testing built in. Keep in mind that it is quite a new feature that will get more love in upcoming releases 🙂 We are in the process of pushing out documentation, but here it is in the meanwhile:

A test in UX consists of an element with a `ux:Test` attribute.  
The value of this attribute determines the name of the test.

```auto
<Panel ux:Test="MyTest">

</Panel>

```

Any JavaScript code that throws an `Error` will make the test fail.

```auto
<Panel ux:Test="MyTest">
	<JavaScript>
		throw new Error("This will always fail");
	</JavaScript>
</Panel>

```

Pure JavaScript tests are also possible using `JavaScriptTest`:

```auto
<JavaScriptTest ux:Test="MyJsTest" File="myJsTest.js" />

```

To run your tests, open a command-line shell and execute the following:

```auto
uno test <path-to-unoproj>

```

Where `<path-to-unoproj>` is the path to your Fuse project’s `.unoproj` file.

---

<div class="post-metadata">

**Author:** ![Filipe\_Almeida](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Filipe\_Almeida](https://forums.fusetools.com/u/Filipe_Almeida)\
**Post date:** [May 31, 2017, 2:06pm UTC](https://forums.fusetools.com/t/unit-testing/1254/3 "2017-05-31T14:06:17Z")

</div>

Hello!

I want only to test Javascript in an automated manner; the later objective is to have it on CI. I also have that issue on my macbook air not being able to preview; so this is the only way i have to proceed. Anyway, i made a lot of attempts and still failed to make it work.

Does the tag `JavaScriptTest` must be inside any specific environment?

Do you have any working example of this?

Cheers.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Reinhard](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/sebastian_reinhard/32/513_2.png) [@Sebastian\_Reinhard](https://forums.fusetools.com/u/Sebastian_Reinhard)\
**Post date:** [June 1, 2017, 10:58am UTC](https://forums.fusetools.com/t/unit-testing/1254/4 "2017-06-01T10:58:42Z")

</div>

Hi! That’s too bad, I hope your preview issue gets fixed quickly.

Anyway, I created a little project that contains the basics for JS testing. When running `uno test test-test.unoproj`, there should be one failing and one passing test.

- [test-test-zip](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/10Poxx2i0Vaq-image-1496314221129.zip)

Let me know if it works 🙂

---

<div class="post-metadata">

**Author:** ![Filipe\_Almeida](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Filipe\_Almeida](https://forums.fusetools.com/u/Filipe_Almeida)\
**Post date:** [June 5, 2017, 3:43pm UTC](https://forums.fusetools.com/t/unit-testing/1254/5 "2017-06-05T15:43:14Z")

</div>

Hello!

Thanks! It works, and it kinda works with the debugger also with the additional params `--run-local --target=dotnet -DDEBUG_V8`; the only problem i had with this is that using webstorm, it does not correctly map the files;

Another thing, but might be my laptop, is that it takes ~17sec to ~200sec(fresh) to build and run tests.

Anyway, as it was a bit slow to make a productive tdd test/code cycle I ended up exploring the apk and manually importing the FuseJS/Observable! Now i can debug and run js tests using node in less than 1 second.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [June 5, 2017, 4:22pm UTC](https://forums.fusetools.com/t/unit-testing/1254/6 "2017-06-05T16:22:08Z")

</div>

Hi Filipe,

would you mind explaining your setup / approach in more details? It might just be something that others could pick up and use.
