레이블이 AngularJS인 게시물을 표시합니다. 모든 게시물 표시
레이블이 AngularJS인 게시물을 표시합니다. 모든 게시물 표시

2015년 7월 4일 토요일

angularjs unittest

0. prepare project for unitest
We need angular-mocks.js. You can download it from http://angularjs.org and https://code.angularjs.org/1.4.1/. I recommend to read the post before following this post if you are not familiar with angularjs and nodejs.

$ tree angularjs-unittest/
|____
| |____angular-animate.js
| |____angular-mocks.js
| |____angular-route.js
| |____angular-sanitize.js
| |____angular-touch.js
| |____angular.js
| |____bootstrap-theme.css
| |____bootstrap.css

1. configure Karma test-runner
You should configure karma per each project respectively . You can see the following questions.
$ karma init karma.config.js

karma.config.js is created.
|____angular-animate.js
|____angular-mocks.js
|____angular-route.js
|____angular-sanitize.js
|____angular-touch.js
|____angular.js
|____bootstrap-theme.css
|____bootstrap.css
|____karma.config.js

2. create unit test file in tests
|____angular-animate.js
|____angular-mocks.js
|____angular-route.js
|____angular-sanitize.js
|____angular-touch.js
|____angular.js
|____bootstrap-theme.css
|____bootstrap.css
|____karma.config.js
|____tests
| |____hellotest.js

3. start karma
$ karma start karma.config.js








We used jasmine testing framework. You may noticed that second test case is failed. Whenever you make changes, Karma automatically detect changes and run all unit test.

2015년 7월 2일 목요일

angularjs development environment

0. description
command : need to type command  from shell
files : represent source files or related files in specific location

1. install node.js
You can install node.js from https://nodejs.org/.

2. install connect, serve-static
$ npm install connect
$ npm install serve-static

3. create server.js
make nodejs dir(any directory is ok). Refer following directory structure which i used.
|____
| |____angularjs
| | |____angular-animate.js
| | |____angular-mocks.js
| | |____angular-route.js
| | |____angular-sanitize.js
| | |____angular-touch.js
| | |____angular.js
| | |____bootstrap-theme.css
| | |____bootstrap.css
| | |____test.html
| |____nodejs
| | |____server.js

The important thing is the line 4. You should set correct path which contains angularjs app.
nodejs/server.js
4. install karma
$ npm install -g karma

5. download AngularJS
https://www.angularjs.org/

6. make angularjs directory and copy files. The directory should be set from server.js
angularjs/angular-animate.js
angularjs/angular-mocks.js
angularjs/angular-route.js
angularjs/angular-sanitize.js
angularjs/angular-touch.js
angularjs/angular.js

7. download bootstrap
http://getbootstrap.com/
copy css file to angularjs directory
angularjs/bootstrap-theme.css
angularjs/bootstrap.css

8. create test.html file in angularjs directory
angularjs/test.html

9. move to nodejs directory and run following command
$ node server.js

10. open browser and go to http//localhost:5000/test.html