Dmytro Golysh
Okay, we have tests.
What next?
Continuous Integration
Frameworks for unit testing in JavaScript
Enzyme
Jest
E2E or Accepting testing
(Gherkin)
Jasmine's syntax
describe("A suite is just a function", function() {
var a;
it("and so is a spec", function() {
a = true;
expect(a).toBe(true);
});
});Chai sinon `should` syntax
describe("A suite is just a function", function() {
var a;
it("and so is a spec", function() {
a = true;
a.should.be.true;
});
});Approaches to write unit tests
Stub everything
describe('CompanyModule:: CompanyHome Component', () => {
let sut;
let store;
let route;
beforeEach(() => {
store = jasmine.createSpyObj('store', [
'dispatch'
]);
route = {
snapshot: {
data: {
company: {}
}
}
};
sut = new CompanyHomeComponent(store, route);
});Use real dependencies
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
describe('CompanyModule:: CompanyHome Component', () => {
let sut;
beforeEach(() => {
spyOn(store, 'dispatch');
sut = new CompanyHomeComponent(Store, ActivatedRoute);
});Approaches to write unit tests
Use compiled component Dom as entry point
Enzyme (React)
TestBed (Angular2)
Approaches to write unit tests
Driver
Navigator
Knowledge sharing
Ping-pong technique
Change driver after each 25 mins
If the driver is silent, the navigator should intervene
Silent coding
TDD is good for tasks with many conditions and bad for spikes
KISS
Keep It Simple, Stupid
YAGNI
You Ain't Gonna Need It