Skip to content

Commit 21b86cd

Browse files
committedJun 10, 2020
add jasmine tests to cover invalid inputs in Lib.coerce2
1 parent cf7c061 commit 21b86cd

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
 

‎test/jasmine/tests/lib_test.js

+68
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,74 @@ describe('Test lib.js:', function() {
798798
expect(sizeOut).toBe(outObj.testMarker.testSize);
799799
});
800800

801+
it('should set the user input', function() {
802+
var colVal = 'red';
803+
var sizeVal = '1e2';
804+
var attrs = {
805+
testMarker: {
806+
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
807+
testSize: {valType: 'number', dflt: 20}
808+
}
809+
};
810+
var obj = {testMarker: {testColor: colVal, testSize: sizeVal}};
811+
var outObj = {};
812+
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
813+
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
814+
815+
expect(colOut).toBe('red');
816+
expect(colOut).toBe(outObj.testMarker.testColor);
817+
expect(sizeOut).toBe(100);
818+
expect(sizeOut).toBe(outObj.testMarker.testSize);
819+
});
820+
821+
it('should set to template if the container input is not valid', function() {
822+
var attrs = {
823+
testMarker: {
824+
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
825+
testSize: {valType: 'number', dflt: 20}
826+
}
827+
};
828+
var obj = {
829+
testMarker: {testColor: 'invalid', testSize: 'invalid'}
830+
};
831+
var outObj = {
832+
_template: {
833+
testMarker: {testColor: 'red', testSize: '1e2'}
834+
}
835+
};
836+
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
837+
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
838+
839+
expect(colOut).toBe('red');
840+
expect(colOut).toBe(outObj.testMarker.testColor);
841+
expect(sizeOut).toBe(100);
842+
expect(sizeOut).toBe(outObj.testMarker.testSize);
843+
});
844+
845+
it('should set to default if the both container and template inputs are not valid', function() {
846+
var attrs = {
847+
testMarker: {
848+
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
849+
testSize: {valType: 'number', dflt: 20}
850+
}
851+
};
852+
var obj = {
853+
testMarker: {testColor: 'invalid', testSize: 'invalid'}
854+
};
855+
var outObj = {
856+
_template: {
857+
testMarker: {testColor: 'invalid', testSize: 'invalid'}
858+
}
859+
};
860+
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
861+
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
862+
863+
expect(colOut).toBe('rgba(0, 0, 0, 0)');
864+
expect(colOut).toBe(outObj.testMarker.testColor);
865+
expect(sizeOut).toBe(20);
866+
expect(sizeOut).toBe(outObj.testMarker.testSize);
867+
});
868+
801869
it('should return false if there is no user input', function() {
802870
var colVal = null;
803871
var sizeVal; // undefined

0 commit comments

Comments
 (0)
Please sign in to comment.