[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 /** 2 * @requires javelin-behavior 3 */ 4 describe('Javelin Behaviors', function() { 5 6 beforeEach(function() { 7 // Don't try this at home, kids. 8 JX.behavior._behaviors = {}; 9 JX.behavior._initialized = {}; 10 JX.behavior._statics = {}; 11 }); 12 13 it('JX.behavior should not work with clowny names', function() { 14 ensure__DEV__(true, function() { 15 expect(function() { 16 JX.behavior('toString', function() {}); 17 }).toThrow(); 18 }); 19 }); 20 21 it('JX.initBehavior should pass a config object', function() { 22 var called = false; 23 var config = 'no-value'; 24 25 JX.behavior('my-behavior', function(cfg) { 26 called = true; 27 config = cfg; 28 }); 29 30 JX.initBehaviors({}); 31 expect(called).toBe(false); 32 expect(config).toEqual('no-value'); 33 34 called = false; 35 config = null; 36 JX.initBehaviors({ 'my-behavior': [] }); 37 expect(called).toBe(true); 38 expect(config).toBeNull(); 39 40 called = false; 41 config = null; 42 JX.initBehaviors({ 'my-behavior': ['foo'] }); 43 expect(called).toBe(true); 44 expect(config).toEqual('foo'); 45 }); 46 47 it('JX.initBehavior should init a behavior with no config once', function() { 48 var count = 0; 49 JX.behavior('foo', function() { 50 count++; 51 }); 52 JX.initBehaviors({ 'foo': [] }); 53 expect(count).toEqual(1); 54 JX.initBehaviors({ 'foo': [] }); 55 expect(count).toEqual(1); 56 JX.initBehaviors({ 'foo': ['test'] }); 57 expect(count).toEqual(2); 58 }); 59 60 it('Behavior statics should persist across behavior invocations', function() { 61 var expect_value; 62 var asserted = 0; 63 JX.behavior('static-test', function(config, statics) { 64 statics.value = (statics.value || 0) + 1; 65 expect(statics.value).toBe(expect_value); 66 asserted++; 67 }); 68 69 expect_value = 1; 70 JX.initBehaviors({'static-test' : [{ hog : 0 }]}); 71 expect_value = 2; 72 JX.initBehaviors({'static-test' : [{ hog : 0 }]}); 73 74 // Test that we actually invoked the behavior. 75 expect(asserted).toBe(2); 76 }); 77 78 it('should throw for undefined behaviors', function() { 79 var called; 80 JX.behavior('can-haz', function() { 81 called = true; 82 }); 83 84 expect(function() { 85 JX.initBehaviors({ 86 'no-can-haz': [], 87 'can-haz': [], 88 'i-fail': [] 89 }); 90 }).toThrow(); 91 92 expect(called).toBe(true); 93 }); 94 95 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |