Fix isDateLine function to check for null and undefined (#4142)

* Fix isDateLine function to check for null and undefined

* use optional chaining instead

Co-Authored-By: Amit Uttam <changingrainbows@gmail.com>

Co-authored-by: Amit Uttam <changingrainbows@gmail.com>
This commit is contained in:
Elias Nahum 2020-04-10 20:19:43 -04:00 committed by GitHub
parent b450c4ac9a
commit f6defc8cc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -836,6 +836,8 @@ describe('makeCombineUserActivityPosts', () => {
describe('isDateLine', () => {
test('should correctly identify date line items', () => {
expect(isDateLine(undefined)).toBe(false);
expect(isDateLine(null)).toBe(false);
expect(isDateLine('')).toBe(false);
expect(isDateLine('date')).toBe(false);
expect(isDateLine('date-')).toBe(true);

View file

@ -114,7 +114,7 @@ export function makeFilterPostsAndAddSeparators() {
// Flip it back to newest to oldest
return out.reverse();
}
},
);
}
@ -182,7 +182,7 @@ export function isStartOfNewMessages(item: string) {
}
export function isDateLine(item: string) {
return item.startsWith(DATE_LINE);
return Boolean(item?.startsWith(DATE_LINE));
}
export function getDateForDateLine(item: string) {
@ -290,7 +290,7 @@ export function makeGenerateCombinedPost() {
user_id: '',
metadata: {},
};
}
},
);
}