Newbie in Vue Javascript tests? Many tools? I’m too, look how I started!

Ramon Schmidt — @ramon_src
3 min readDec 23, 2017

--

As a newbie in tests and js tests, I was looking for tutorials in web about best practices to test components, ways to test vuejs, best practices in general, good test tools, tutorials about TDD and BDD and so on.

When I came across with the following things: Jest, AVA, Mocha, Chai, Sinon, Karma, Jasmine, Avoriaz, vue-test-utils, tape, jsdom, testcafe, PhantomJs…

OMFG, where do I START?

So that is why I decided to write this story. My difficult to choose and understand what is the best and commonly test’s tools which the community use and what is the best choice to write Vue js tests!

The second thing that I think, is how can I understand that whole of contents and explain for you! Well… I can start categorizing everything!

Sooo let’s start!

Test Runners

Wow, what is that? Well test runners are libraries or tools with a bunch of settings for run yours test’s files. That has many command lines which you will configure how to run your tests, and show the results of assertions or failures.

Ok, I did a research and found this test runners for Javascript:

  • tape
  • Jasmine
  • AVA
  • Mocha
  • Jest

Tape

This framework maintains a fairly minimal core. The native report is poor, so many people use libraries to be more colorful and pretty. As well Tape is a really minimal test framework, have a lot of additional features that you can plug in, and mainly serves its purpose, to test.

Jasmine

Simple and complete BDD framework . So Jasmine has its own spy and assertions methods.

AVA

Takes advantage running tests concurrently, especially beneficial for IO heavy tests. The guys that created ensure that is a minimal, fast and clean framework, simple test syntax, enforces writing atomic tests and have no implicit globals.

Mocha

As the creators describe, this framework is a feature-rich Javascript test framework. Which has so many features this you can configure as you like. Many people argue whether this is good or not. Mocha for spies and assertions needs two dependencies Sinon and Chai wich we will talk about later.

Jest

From Facebook, Jest is a “Zero configuration testing platform”. Runs in parallel like AVA to maximize performance, has automatic global state resets for every test, easily create code coverage reports… So Jest is an another complete and rich framework but you don’t need to CONFIGURE!

About Behavior Driven Development (BDD)

If you don’t know what is BDD, I explain! It was inspired by agile methodologies with the purpose to approximate business language in technical context.

As well as tests must be used like documentation of your code base, BDD brings the agile approach of business documentation: acceptance criteria and scenarios, to code.

Ruby Test using RBehave

Newer BDD frameworks are using specification language rather than user stories. Where the developers can write tests with a free format using method describe to describe the suite of tests and it to describe what that unit test must do.

Javascript test using Mocha

FATALITY

For my conclusions everyone hate and love Mocha. Love their rich features, active community, performance. But hate the global functions and shared states, much configuration to start and serializing tests.

AVA says they are fast but this benchmark don’t say the same. But about IO, I really don’t know how fast he is.

Many people who defend tape are sure about the minimal framework is all about: Test assertions should be dead simple, & completely free of magic.

Others like Jasmine, for your simplicity and BDD native language. Jasmine and Tape have a good performance.

At least and no less important Jest! Is another complete framework ready-to-use. The Jest’s philosophy is provide no configuration tools, because they believe the engineers write more tests, which in turn results in more stable and healthy code.

Conclusion

Well, now I learned and did my first share!!! With that simple story to decrease my little pain about that huge javascript ecosystem. I think that me and you are in the same way, so lets learn together!

Now we know a little bit about the tools, test runners itself and BDD!!! \o/

The next will be about Avoriaz and vue-test-utils and a little start about principles to test components.

Heey, do you like how I wrote? Feel free to give me some tips and comments!

--

--

Ramon Schmidt — @ramon_src

Technology enthusiast, student for life, front-back developer. Love indie music, freedom, coffee, beer, make friends, travel and events!