From 7ec2382d1ee16116a9dea75659ee3704614bd345 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Wed, 28 Mar 2018 13:19:37 +0200 Subject: [PATCH] mocks Jasmine : argument optionnel pour toBeTruthy() et toBeFalsy(), correction bug dans toBeUndefined() et toThrow() --- spec/mock_jasmine.ts | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/spec/mock_jasmine.ts b/spec/mock_jasmine.ts index 61bae1f5..17bffedd 100644 --- a/spec/mock_jasmine.ts +++ b/spec/mock_jasmine.ts @@ -92,9 +92,13 @@ class Expect { * Mock de la fonction toBeTruthy de Jasmine : the actual value should be true * @param message message d'erreur */ - public toBeTruthy(message: string) { + public toBeTruthy(message?: string) { if (!this.actual) { - console.error(message); + if (message !== undefined) { + console.error(message); + } else { + console.error(`${this.actual} should be true`); + } } } @@ -102,23 +106,27 @@ class Expect { * Mock de la fonction toBeFalsy de Jasmine : the actual value should be false * @param message message d'erreur */ - public toBeFalsy(message: string) { + public toBeFalsy(message?: string) { if (this.actual) { - console.error(message); + if (message !== undefined) { + console.error(message); + } else { + console.error(`${this.actual} should be false`); + } } } public toBeUndefined(message?: string) { if (this.actual !== undefined) { - if (message === undefined) { + if (message !== undefined) { console.error(message); } else { - console.error(this.actual + " should be undefined"); + console.error(`${this.actual} should be undefined`); } } } - public toThrow(expected: any) { + public toThrow(expected?: any) { let exception: Error; if (typeof this.actual !== "function") { throw new Error("Actual is not a function"); @@ -128,11 +136,16 @@ class Expect { } catch (e) { exception = e; } - if (exception) { - if (exception === undefined) { - console.error("Expected tested function to thow an error"); - } else if (exception.message !== expected.message) { - console.error("Function throws " + exception.message + " and " + expected.message + " was expected"); + if (exception === undefined) { + console.error("Expected tested function to throw an error"); + } else { + if (expected) { + if (exception.message !== expected.message) { + console.error(`Function throws '${exception.message}' but '${expected.message}' was expected`); + } + } + else if (exception.message) { + console.error(`Function throws '${exception.message}' but no message was expected`); } } } -- GitLab