From f6defc8cc6534b5ecb7764245f3a1abb415e466b Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 10 Apr 2020 20:19:43 -0400 Subject: [PATCH] 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 Co-authored-by: Amit Uttam --- app/mm-redux/utils/post_list.test.js | 2 ++ app/mm-redux/utils/post_list.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/mm-redux/utils/post_list.test.js b/app/mm-redux/utils/post_list.test.js index 2cecd5631..5decd0830 100644 --- a/app/mm-redux/utils/post_list.test.js +++ b/app/mm-redux/utils/post_list.test.js @@ -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); diff --git a/app/mm-redux/utils/post_list.ts b/app/mm-redux/utils/post_list.ts index 2fc4822b9..628de23e4 100644 --- a/app/mm-redux/utils/post_list.ts +++ b/app/mm-redux/utils/post_list.ts @@ -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: {}, }; - } + }, ); }