Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/normandy72/testing-with-jasmine

Testing Javascript with Jasmine. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.
https://github.com/normandy72/testing-with-jasmine

angular angularjs css css3 html html5 jasmine jasmine-tests javascript js testing unit-test

Last synced: about 2 months ago
JSON representation

Testing Javascript with Jasmine. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.

Awesome Lists containing this project

README

        

# Testing Javascript with Jasmine
### unit testing
Independent checking for proper operation of the smallest testable part of an application.
* Independent: isolated from the rest of the system.
* Smallest testable: means you have to approach the all of code development from this prospective.
* Should be repeatable.

### mocking
Technique where dependency and its behavior is imitated (or faked).
* Can be done by the developer or a mocking library.
### Steps for Jasmine-based Tests
* Download and unzip Jasmine standalone into a directory.
[https://github.com/jasmine/jasmine/releases]()
* Erase everything in src and spec directories.
* Place your application code into the src directory.
* Place test code or a spec into the spec directory.
* Update SpecRunner.thml
* Replace references to erased src and spec files with yours.
* Start Browser-sync (or whatever you use for local server) and go to the `http://.../SpecRunner.html` to have your specs run.

### Writing a Spec (test)
```
describe("My Function", function(){
var initValue;

beforeEach(function(){
initValue = "someVal";
});

it("should not return true", function(){
var result = someFunc(initValue);
expect(result).not.toBe(true);
});
});
```
***
#### _Summary_
* Unit testing is an essential process in any software dev. Planning for unit testing changes how you write code (for the better).
* Mocks are used to fake the dependencies of target code.
* `describe("message", function(){})` is to used to group tests together.
* `beforeEach(function(){})` is used to initialize state before running each test.
* `it("message", function(){actual test})` is used to run the actual test code.
***