Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d81b8c2

Browse files
committed
🐅 add test for enumerated types coerce
1 parent 5453643 commit d81b8c2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/jasmine/tests/lib_test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,44 @@ describe('Test lib.js:', function() {
588588

589589

590590
});
591+
592+
describe('enumerated types', function() {
593+
var attrs = {
594+
a: { valType: 'enumerated', dflt: 8, coerceNumber: true, values: [2, 'e', true, 8] },
595+
b: { valType: 'enumerated', dflt: 8, values: [2, 'e', true, 8] }
596+
};
597+
598+
it('should allow only the enum values', function() {
599+
out = coerce(undefined, {}, attrs, 'a');
600+
expect(out).toBe(8);
601+
});
602+
603+
it('should be strict about numbers when coerceNumber isn\'t set', function() {
604+
out = coerce({ b: '2' }, {}, attrs, 'b');
605+
expect(out).toBe(8);
606+
});
607+
608+
it('should coerce when coerceNumber is set', function() {
609+
out = coerce({ a: '2' }, {}, attrs, 'a');
610+
expect(out).toBe(2);
611+
});
612+
613+
it('should use the default when given an invalid value', function() {
614+
out = coerce({ a: 'invalid' }, {}, attrs, 'a');
615+
expect(out).toBe(8);
616+
});
617+
618+
it('should work with mixed types', function() {
619+
out = coerce({ a: true }, {}, attrs, 'a');
620+
expect(out).toBe(true);
621+
622+
out = coerce({ a: 'e' }, {}, attrs, 'a');
623+
expect(out).toBe('e');
624+
625+
out = coerce({ a: 2 }, {}, attrs, 'a');
626+
expect(out).toBe(2);
627+
});
628+
});
591629
});
592630

593631
describe('coerceFont', function() {

0 commit comments

Comments
 (0)