Dmytro Golysh
Agenda:
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
Frameworks for unit testing in JavaScript
Enzyme
Jest
Suitable for any UI framework
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;
});
});
Let's jump to real example
describe("A suite is just a function", function() {
var a;
it("and so is a spec", function() {
a = true;
expect(a).toBe(true);
});
});
Let's jump to real example
Best friend of Angular
Let's jump to real example
Best friend of React
Let's jump to real example
Best friend of React
Enzyme
For testing DOM manipulation in component
E2E or Accepting testing
(Gherkin)
Driver
Navigator
Knowledge sharing
Ping-pong technique
Change driver after each 25 mins
If the driver is silent, the navigator should intervene
Silent coding
KISS
Keep It Simple, Stupid
YAGNI
You Ain't Gonna Need It
DRY
Don't repeat yourself
SOC
Separation of Concerns
Write angular functionality in TDD from scratch
Link to examples: