to the given URL', function() { spyOn(window.location, 'replace'); redirect('http://google.com'); expect(window.location.replace).toHaveBeenCalledWith(' http://google.com'); });
var oldDate = Date; spyOn(window, 'Date').and.callFake(function() { return new oldDate('2014-03-30'); }); var d = new Date(); expect(d.getFullYear()).toEqual(2014); });
{ var div = document.createElement('div'); div.innerHTML = 'Unit test all the things!'; document.body.appendChild(div); expect(div.offsetHeight).toBeGreaterThan(0); div.remove(); });
own implementation of require() similar to node.js ➤We need to be able to mock libraries included by require() ➤This can be done in two ways: creating a proxy for require() or monkey patching
a separate feature ➤Independent - tests should not rely on each other ➤Easy to write - as much as the rest of the code ➤Fast - better performance means more tests runs