Options, specs
This commit is contained in:
parent
36f7ada676
commit
14bd27b088
@ -18,6 +18,7 @@
|
||||
<script type="text/javascript" src="../src/core/Util.js"></script>
|
||||
<script type="text/javascript" src="../src/core/Class.js"></script>
|
||||
<script type="text/javascript" src="../src/core/Events.js"></script>
|
||||
<script type="text/javascript" src="../src/core/Options.js"></script>
|
||||
|
||||
<!-- /geometry -->
|
||||
<script type="text/javascript" src="../src/geometry/Point.js"></script>
|
||||
@ -31,6 +32,7 @@
|
||||
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/core/ClassSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/core/EventsSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/core/OptionsSpec.js"></script>
|
||||
|
||||
<!-- /geometry -->
|
||||
<script type="text/javascript" src="suites/geometry/PointSpec.js"></script>
|
||||
|
37
spec/suites/core/OptionsSpec.js
Normal file
37
spec/suites/core/OptionsSpec.js
Normal file
@ -0,0 +1,37 @@
|
||||
describe('Options', function() {
|
||||
var Klass;
|
||||
|
||||
beforeEach(function() {
|
||||
Klass = L.Class.extend({
|
||||
options: {
|
||||
foo1: 1,
|
||||
foo2: 2
|
||||
},
|
||||
|
||||
includes: [L.Mixin.Options]
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setOptions', function() {
|
||||
it('should set the given options, overwriting the default ones', function() {
|
||||
var a = new Klass();
|
||||
|
||||
expect(a.options).toEqual({foo1: 1, foo2: 2});
|
||||
|
||||
a.setOptions({foo2: 3, foo3: 4});
|
||||
|
||||
expect(a.options).toEqual({foo1: 1, foo2: 3, foo3: 4});
|
||||
});
|
||||
|
||||
it('should fire optionschange event if Options module is availalbe', function() {
|
||||
Klass.include(L.Mixin.Events);
|
||||
var a = new Klass(),
|
||||
spy = jasmine.createSpy('optionschange handler');
|
||||
|
||||
a.on('optionschange', spy);
|
||||
a.setOptions({foo1: 3});
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
14
src/core/Options.js
Normal file
14
src/core/Options.js
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* L.Mixin.Options adds a small shortcut for options handling
|
||||
*/
|
||||
|
||||
L.Mixin.Options = {
|
||||
setOptions: function(/*Object*/ options) {
|
||||
this.options = this.options || {};
|
||||
L.Util.extend(this.options, options);
|
||||
|
||||
if (this.fireEvent) {
|
||||
this.fireEvent('optionschange');
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user