Slide 1

Slide 1 text

An exciting intro to Javascript unit testing Juan Lizarazo @juanlizarazog 2019 UtahJS Conference

Slide 2

Slide 2 text

Hi I am Juan Lizarazo @juanlizarazog

Slide 3

Slide 3 text

No, this talk is not about AMP :) Still, check it out at https://amp.dev

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

An exciting intro to Javascript unit testing @juanlizarazog

Slide 6

Slide 6 text

Unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use. @juanlizarazog

Slide 7

Slide 7 text

How to make unit testing exciting? @juanlizarazog

Slide 8

Slide 8 text

Let’s face it:
 
 Unit testing is boring! @juanlizarazog

Slide 9

Slide 9 text

But learning about it doesn’t have to be! @juanlizarazog

Slide 10

Slide 10 text

•Testing individual units of code • Unit is the smallest testable part What is unit testing? @juanlizarazog

Slide 11

Slide 11 text

•Trust changes you make on existing (already tested) code. •Code quality •Changes occur quickly •Documents your own code •Automation Why? @juanlizarazog

Slide 12

Slide 12 text

How do we unit test JavaScript? @juanlizarazog

Slide 13

Slide 13 text

1. Pick a library or framework @juanlizarazog

Slide 14

Slide 14 text

2. Learn some core concepts @juanlizarazog

Slide 15

Slide 15 text

1. Learn some key concepts @juanlizarazog @juanlizarazog Expectations •Test the state of the code expect(1 + 1).toBe(2);

Slide 16

Slide 16 text

1. Learn some key concepts @juanlizarazog @juanlizarazog Matchers •It’s just a function •Implements a boolean comparison expect(1 + 1).toBe(2);

Slide 17

Slide 17 text

1. Learn some key concepts @juanlizarazog @juanlizarazog Specs •Short of specification •Group of expectations (that test the state of the code). •spec -> test test('adds 1 + 1 to equal 2', () => {
 expect(sum(1, 1)).toBe(2);
 });

Slide 18

Slide 18 text

1. Learn some key concepts @juanlizarazog @juanlizarazog Specs •Short of specification •Group of expectations (that test the state of the code). •spec -> test it('adds 1 + 1 to equal 2', () => {
 expect(sum(1, 1)).toBe(2);
 });

Slide 19

Slide 19 text

1. Learn some key concepts @juanlizarazog @juanlizarazog Suites •Group of tests •Help us organize our units describe('sum()', () => {
 // specs
 });

Slide 20

Slide 20 text

3. Do not test implementation details! Ever! I mean it. # @juanlizarazog

Slide 21

Slide 21 text

@juanlizarazog test('adds 1 + 2 to equal 3', () => {
 expect(sum(1, 2)).toBe(3);
 }); function sum(a, b) {
 // return b + a;
 // return a + b;
 // return Number.parseInt(a, 10) + Number.parseInt(b, 10);
 // or anything else, we just care that the result is the sum
 }

Slide 22

Slide 22 text

4. Write tests! @juanlizarazog

Slide 23

Slide 23 text

Recap 1. Pick a library or framework 2. Learn some core concepts 3. Do not test implementation details 4. Write tests! @juanlizarazog

Slide 24

Slide 24 text

UTAHJS2019 Enroll for free, use this code at checkout (10 available) @juanlizarazog

Slide 25

Slide 25 text

Technology is our friend — @juanlizarazog

Slide 26

Slide 26 text

Thank you!!! Udemy: https://www.udemy.com/course/unit-testing-your-javascript-with-jasmine/ Slides: https://speakerdeck.com/juanlizarazo @juanlizarazog