Testowanie JavaScript
Przydatne linki
- Artykuł o testach jednostkowych, integracyjnych i funkcjonalnych - JavaScript Testing: Unit vs Functional vs Integration Tests
- Karma i Jasmine wstęp (po polsku)
-
AngularJS
- Angular Unit Testing Quick Start - testowanie jednostkowe w Karma
- Unit Testing Best Practices in AngularJS - testowanie jednostkowe Jasmine BDD/Mocha jak i testowanie integracyjne w Karma
- Testing AngularJS with Jasmine and Karma - tutorial testowania aplikacji
- Unit Testing - dokumentacja AngularJS o testowaniu jednostkowym z wykorzystaniem Jasmine BDD/Karma
- E2E Testing - dokumentacja AngularJS o testowaniu E2E w Protractor
-
Testowanie Node.js
Jest
Jest is testing platform. It has builtin features like test runner, test framework, assertion lib and mock lib. So in that way it is similar to Karma + Mocha + Chai + Sinon.
Karma
Karma is a test runner.
Mocha
Mocha is testing framework. It provides methods like describe
, it
, etc.
Chai
Chai is an assertion library. There is also library chai-as-promised
which enables possibility to test asynchronus code.
Sinon
Sinon and Sinon-Chai is a library for mocking.
Enzyme
Enzyme is library which allows testing React components. It provides bindings for Chai and Jest.
Terminology
Spies: Creates fake functions which we can use to track executions. This means we can tell/ find out whether the function has been executed/ how many times its been called etc. We can also use spies on existing functions and get the same capability, to track those functions executions. We'll see this in action a bit later.
Stubs: Enables us to replace functions. This gives us more control. We can return whatever we want or have our functions work in a way that suites us to be able to test multiple scenarios.
Mocks: They are fake methods, that have pre-programmed behavior and pre-programmed expectations.
Source