From a4c38168ad6e229d9438fe90bae0c03f8df8cea1 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Fri, 20 Mar 2020 22:50:28 +0100 Subject: [PATCH] Added first real test --- package.json | 4 +++- utils/PlanningEventManager.js | 12 +++++++----- utils/__test__/PlanningEventManager.test.js | 15 ++++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index e5cfed5..d3e83da 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "testc": "jest --coverage" }, "jest": { - "preset": "react-native" + "preset": "react-native", + "setupFilesAfterEnv": ["jest-extended"] }, "dependencies": { "@expo/vector-icons": "~10.0.0", @@ -46,6 +47,7 @@ "devDependencies": { "babel-preset-expo": "^8.0.0", "jest": "^25.1.0", + "jest-extended": "^0.11.5", "react-test-renderer": "^16.13.1" }, "private": true diff --git a/utils/PlanningEventManager.js b/utils/PlanningEventManager.js index b9cb140..db67157 100644 --- a/utils/PlanningEventManager.js +++ b/utils/PlanningEventManager.js @@ -74,10 +74,12 @@ export default class PlanningEventManager { } static isDescriptionEmpty (description: string) { - return description - .replace('

', '') - .replace('

', '') - .replace('
', '').trim() === ''; + if (description !== undefined && description !== null) { + return description + .replace('

', '') + .replace('

', '') + .replace('
', '').trim() === ''; + } else + return true; } - } diff --git a/utils/__test__/PlanningEventManager.test.js b/utils/__test__/PlanningEventManager.test.js index c4f2706..8451850 100644 --- a/utils/__test__/PlanningEventManager.test.js +++ b/utils/__test__/PlanningEventManager.test.js @@ -1,10 +1,15 @@ import React from 'react'; import PlanningEventManager from "../PlanningEventManager"; -test('time test', () => { - expect(PlanningEventManager.formatTime("1:2")).toBe("1:2"); +test('isDescriptionEmpty', () => { + expect(PlanningEventManager.isDescriptionEmpty("")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("

")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("


")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("


")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty(null)).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty(undefined)).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("coucou")).toBeFalse(); + expect(PlanningEventManager.isDescriptionEmpty("

coucou

")).toBeFalse(); }); -test('time test 2', () => { - expect(PlanningEventManager.formatTime("1:2")).toBe("2:2"); -}); +