diff options
| author | Igor Minar | 2012-03-08 15:00:38 -0800 |
|---|---|---|
| committer | Igor Minar | 2012-03-08 22:29:34 -0800 |
| commit | f54db2ccda399f2677e4ca7588018cb31545a2b4 (patch) | |
| tree | 29ef2f8f834544c84cea1a82e3d08679358fb992 /test/directive/ngSwitchSpec.js | |
| parent | dd7b0f56fcd9785f7fccae8c4f088a8f3e7b125e (diff) | |
| download | angular.js-f54db2ccda399f2677e4ca7588018cb31545a2b4.tar.bz2 | |
chore(directives,widgets): reorg the code under directive/ dir
Diffstat (limited to 'test/directive/ngSwitchSpec.js')
| -rw-r--r-- | test/directive/ngSwitchSpec.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/directive/ngSwitchSpec.js b/test/directive/ngSwitchSpec.js new file mode 100644 index 00000000..88e81dea --- /dev/null +++ b/test/directive/ngSwitchSpec.js @@ -0,0 +1,63 @@ +'use strict'; + +describe('ng:switch', function() { + var element; + + + afterEach(function(){ + dealoc(element); + }); + + + it('should switch on value change', inject(function($rootScope, $compile) { + element = $compile( + '<div ng-switch="select">' + + '<div ng:switch-when="1">first:{{name}}</div>' + + '<div ng:switch-when="2">second:{{name}}</div>' + + '<div ng:switch-when="true">true:{{name}}</div>' + + '</div>')($rootScope); + expect(element.html()).toEqual( + '<!-- ngSwitchWhen: 1 --><!-- ngSwitchWhen: 2 --><!-- ngSwitchWhen: true -->'); + $rootScope.select = 1; + $rootScope.$apply(); + expect(element.text()).toEqual('first:'); + $rootScope.name="shyam"; + $rootScope.$apply(); + expect(element.text()).toEqual('first:shyam'); + $rootScope.select = 2; + $rootScope.$apply(); + expect(element.text()).toEqual('second:shyam'); + $rootScope.name = 'misko'; + $rootScope.$apply(); + expect(element.text()).toEqual('second:misko'); + $rootScope.select = true; + $rootScope.$apply(); + expect(element.text()).toEqual('true:misko'); + })); + + + it('should switch on switch-when-default', inject(function($rootScope, $compile) { + element = $compile( + '<ng:switch on="select">' + + '<div ng:switch-when="1">one</div>' + + '<div ng:switch-default>other</div>' + + '</ng:switch>')($rootScope); + $rootScope.$apply(); + expect(element.text()).toEqual('other'); + $rootScope.select = 1; + $rootScope.$apply(); + expect(element.text()).toEqual('one'); + })); + + + it('should call change on switch', inject(function($rootScope, $compile) { + element = $compile( + '<ng:switch on="url" change="name=\'works\'">' + + '<div ng:switch-when="a">{{name}}</div>' + + '</ng:switch>')($rootScope); + $rootScope.url = 'a'; + $rootScope.$apply(); + expect($rootScope.name).toEqual('works'); + expect(element.text()).toEqual('works'); + })); +}); |
