Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Jul 25, 2017
1 parent 157e9bc commit 9fd24e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/lib/core/datetime/native-date-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ describe('NativeDateAdapter', () => {
expect(adapter.parse(date)).not.toBe(date);
});

it('should parse invalid value as null', () => {
expect(adapter.parse('hello')).toBeNull();
it('should parse invalid value as invalid', () => {
let d = adapter.parse('hello');
expect(d).not.toBeNull();
expect(adapter.isDateInstance(d)).toBe(true);
expect(adapter.isValid(d as Date)).toBe(false);
});

it('should format', () => {
Expand Down Expand Up @@ -305,16 +308,24 @@ describe('NativeDateAdapter', () => {
}
});

it('should count a Date as a valid date object', () => {
expect(adapter.isValid(new Date())).toBe(true);
it('should count today as a valid date instance', () => {
let d = new Date();
expect(adapter.isValid(d)).toBe(true);
expect(adapter.isDateInstance(d)).toBe(true);
expect(adapter.getValidDateOrNull(d)).toBe(d);
});

it('should not count a string as a valid date object', () => {
expect(adapter.isValid('1/1/2017')).toBe(false);
it('should count an invalid date as an invalid date instance', () => {
let d = new Date(NaN);
expect(adapter.isValid(d)).toBe(false);
expect(adapter.isDateInstance(d)).toBe(true);
expect(adapter.getValidDateOrNull(d)).toBeNull();
});

it('should not count InvalidDate as a valid date object', () => {
expect(adapter.isValid(new Date(NaN))).toBe(false);
it('should count a string as not a date instance', () => {
let d = '1/1/2017';
expect(adapter.isDateInstance(d)).toBe(false);
expect(adapter.getValidDateOrNull(d)).toBeNull();
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class InputContainerDatepicker {
})
class DatepickerWithMinAndMaxValidation {
@ViewChild('d') datepicker: MdDatepicker<Date>;
date: Date;
date: Date | null;
minDate = new Date(2010, JAN, 1);
maxDate = new Date(2020, JAN, 1);
}
Expand Down

0 comments on commit 9fd24e0

Please sign in to comment.