Unit Testing

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?

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 :slight_smile: 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.

<Panel ux:Test="MyTest">

</Panel>

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

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

Pure JavaScript tests are also possible using JavaScriptTest:

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

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

uno test <path-to-unoproj>

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

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.

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.

Let me know if it works :slight_smile:

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.

Hi Filipe,

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