From a185fc963d152a29a3ecd83cb9cd03dd9882c6f5 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 7 Feb 2014 17:03:39 -0700 Subject: [PATCH] Tests for get/setStyleFunction It would be nice to also test the following: it('does not return user set property with the same name', function() { var feature = new ol.Feature({ whatever: 'some value', styleFunction: 'another value' }); expect(feature.getStyleFunction()).to.be(undefined); }); Unfortunately, in uncompiled code (or if we export `setStyleFunction`) this does not work. Same goes for user set `id` properties (this will set our internal `id_` property). See #1672. --- test/spec/ol/feature.test.js | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/spec/ol/feature.test.js b/test/spec/ol/feature.test.js index ece506aad4..5a07558349 100644 --- a/test/spec/ol/feature.test.js +++ b/test/spec/ol/feature.test.js @@ -207,6 +207,59 @@ describe('ol.Feature', function() { }); + describe('#getStyleFunction()', function() { + + var styleFunction = function(feature, resolution) { + return null; + }; + + it('returns undefined after construction', function() { + var feature = new ol.Feature(); + expect(feature.getStyleFunction()).to.be(undefined); + }); + + it('returns the function passed to setStyleFunction', function() { + var feature = new ol.Feature(); + feature.setStyleFunction(styleFunction); + expect(feature.getStyleFunction()).to.be(styleFunction); + }); + + it('does not get confused with user "styleFunction" property', function() { + var feature = new ol.Feature(); + feature.set('styleFunction', 'foo'); + expect(feature.getStyleFunction()).to.be(undefined); + }); + + // TODO: also assert that 'styleFunction' passed to the constructor is + // not confused with the internal 'styleFunction_'. + // See https://github.com/openlayers/ol3/issues/1672 + + }); + + describe('#setStyleFunction()', function() { + + var styleFunction = function(feature, resolution) { + return null; + }; + + it('sets the style function', function() { + var feature = new ol.Feature(); + feature.setStyleFunction(styleFunction); + expect(feature.getStyleFunction()).to.be(styleFunction); + }); + + it('dispatches a change event', function(done) { + var feature = new ol.Feature(); + feature.on('change', function() { + done(); + }); + feature.setStyleFunction(styleFunction); + }); + + }); + + + }); describe('ol.feature.createStyleFunction()', function() {