http://madroom-project.blogspot.jp/2014/03/gulp-karma-jasmine-phantomjs-angularjs.html
昨夜に作った独自ディレクティブをテストしてみました。
http://madroom-project.blogspot.jp/2014/03/angularjs.html
<div my-keypress-enter="enter(1)"></div>のようなタグがある時にエンターキーが押されたら、対応する $scope.enter() が引数1で呼ばれる。みたいなテストです。
以下、CoffeeScriptですが、テスト(spec)のソースです。
describe 'myKeypressEnterDirective', () ->
it 'should be bind keypress 13', inject ($rootScope, $compile) ->
$scope = $rootScope.$new()
$scope.spyCallback = () ->
spyOn($scope, 'spyCallback')
$element = $compile('<div my-keypress-enter="spyCallback(1)"></div>')($scope)
$element.trigger($.Event('keypress', keyCode: 1))
expect($scope.spyCallback).not.toHaveBeenCalled()
$element.trigger($.Event('keypress', keyCode: 13))
expect($scope.spyCallback).toHaveBeenCalledWith(1)
このやり方で良いのだろうか。(angular-scenario.js http://docs.angularjs.org/misc/downloading も気になる。。。)
No comments:
Post a Comment