Skip to content

Commit

Permalink
ADD test on casting null and undefined scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
stombre committed Oct 27, 2020
1 parent 6717968 commit b24e87b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/SchemaFieldCast.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,41 @@ describe('spec ilorm', () => {
const boolean = new ilorm.Schema.Types.Boolean();

expect(boolean.castValue('true')).to.be.a('boolean');
expect(boolean.castValue(undefined)).to.be.equal(undefined);
expect(boolean.castValue(null)).to.be.equal(null);
});

it('Should cast a date value', () => {
const date = new ilorm.Schema.Types.Date();

expect(date.castValue('11/11/2018')).to.be.a('date');
expect(date.castValue(undefined)).to.be.equal(undefined);
expect(date.castValue(null)).to.be.equal(null);
});

it('Should not create a new date instance when casting', () => {
const date = new ilorm.Schema.Types.Date();
const rawDate = new Date('11/11/2018');

expect(date.castValue(rawDate)).to.be.equal(rawDate);
expect(date.castValue(undefined)).to.be.equal(undefined);
expect(date.castValue(null)).to.be.equal(null);
});

it('Should cast a number value', () => {
const number = new ilorm.Schema.Types.Number();

expect(number.castValue('33')).to.be.a('number');
expect(number.castValue(undefined)).to.be.equal(undefined);
expect(number.castValue(null)).to.be.equal(null);
});

it('Should cast a string value', () => {
const string = new ilorm.Schema.Types.String();

expect(string.castValue(0)).to.be.a('string');
expect(string.castValue(undefined)).to.be.equal(undefined);
expect(string.castValue(null)).to.be.equal(null);
});
});
});

0 comments on commit b24e87b

Please sign in to comment.