Skip to content

Latest commit

 

History

History
109 lines (67 loc) · 3.69 KB

Readme 13.05.md

File metadata and controls

109 lines (67 loc) · 3.69 KB

Today 13.05

The main idea is start the program doing a test

  • The Unit testing --> codigo que comprueba que otro código tiene que hacer lo que debe de hacer.

Ejemplos test:

function(sum) {
  const msg = "hola"
  return [a + b, msg]
}

--> Testing ex for check the code above.

typeof sum === function
sum(2, 5)[0] === 7
sum(2, 5)[1] === "hola"

Example the Unit testing. This example is very simple but illustrate several things about unit testings:

  1. The function is tested from several angles (we check what the function returns when passing different types of data to it)
  2. We compare the returned value with an expected value
  3. If these values match we show a green OK
  4. If these values doesn't match we show an error message to help us locate the problem

unit_testing.png

BDD

especializado en testear en vez del codigo como el TDD este se enfoca en testear partes de la app.

The most populars Jasmine (slide here), QUnit, Mocha, etc...

Now practice with Jasmine. Download Jasmine here and follow the instructions of teacher

Some matchers that Jasmine offer by default (we can build our own) are:

  • expect(x).toEqual(y);
    compares objects or primitives x and y and passes if they are equivalent

  • expect(x).toBe(y);
    compares objects or primitives x and y and passes if they are the same object

  • expect(x).toMatch(pattern);
    compares x to string or regular expression pattern and passes if they match

  • expect(x).toBeDefined();
    passes if x is not undefined

  • expect(x).toBeUndefined();
    passes if x is undefined

  • expect(x).toBeNull();
    passes if x is null

  • expect(x).toBeTruthy();
    passes if x evaluates to true

  • expect(x).toBeFalsy();
    passes if x evaluates to false

  • expect(x).toContain(y);
    passes if array or string x contains y

  • expect(x).toBeLessThan(y);
    passes if x is less than y

  • expect(x).toBeGreaterThan(y);
    passes if x is greater than y

  • expect(function(){fn();}).toThrow(e);
    passes if function fn throws exception e when executed

Kata

For practice TDD in slide 62

Drink Beer

For practice TDD in slide 63

Overcomplexity (overcomplexity programming)

Grade Book

For practice TDD in slide 64

Fizz Buzz

Practice online here

This web for practice http://cyber-dojo.org/setup_default_start_point/show_exercises/?language=Javascript&test=jasmine