Testing Flashcards

1
Q

Koans Testing

A
// Some ways of asserting equality are better than others.
  it("should assert equality a better way", function() { 
	  var expectedValue = 2;
	  var actualValue = 1 + 1;
  // toEqual() compares using common sense equality.
	  expect(actualValue).toEqual(expectedValue);
  });
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Array References - trouble spot

A
it("should know array references", function() {
    var array = [ "zero", "one", "two", "three", "four", "five" ];
    function passedByReference(refArray) {
      refArray[1] = "changed in function";
    }
    passedByReference(array);
    expect(array[1]).toBe("changed in function");
    var assignedArray = array;
    assignedArray[5] = "changed in assignedArray";
    expect(array[5]).toBe("changed in assignedArray");
    var copyOfArray = array.slice();
    copyOfArray[3] = "changed in copyOfArray";
    expect(array[3]).toBe("three");
  });
How well did you know this?
1
Not at all
2
3
4
5
Perfectly