From b8a9826f23b2bdd6c3345ab93db6b53f7e6e2ae8 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Sat, 9 Jan 2021 15:53:17 -0500 Subject: [PATCH] Cleaned up jasmine test suite output (#5377) * Cleaned up jasmine test suite output Also testing for expected log messages, instead of just letting them print to the console every single time, constantly making you think there's some warning you need to worry about, and making all those dots not line up nicely. * switched single quotes to double in collectLogs --- editions/test/tiddlers/tests/test-filters.js | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 0dbb9723b..a820c4d04 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -14,6 +14,22 @@ Tests the filtering mechanism. /* global $tw, require */ "use strict"; +// This wrapper method is used to collect warnings which should be emitted +// by certain deprecated tests. +function collectLog(block) { + var messages = []; + var oldLog = console.log; + console.log = function(a) { + messages.push(Array.prototype.join.call(arguments, " ")); + } + try { + block(); + } finally { + console.log = oldLog; + } + return messages; +}; + describe("Filter tests", function() { // Test filter parsing @@ -249,8 +265,14 @@ function runTests(wiki) { // The following 2 tests should write a log -> WARNING: Filter modifier has a deprecated regexp operand XXXX // The test should pass anyway. it("should handle the field operator with a regular expression operand", function() { - expect(wiki.filterTiddlers("[modifier/JoeBloggs/]").join(",")).toBe("TiddlerOne"); - expect(wiki.filterTiddlers("[modifier/Jo/]").join(",")).toBe("TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one"); + var warnings = collectLog(function() { + expect(wiki.filterTiddlers("[modifier/JoeBloggs/]").join(",")).toBe("TiddlerOne"); + }); + expect(warnings).toEqual(["WARNING: Filter modifier has a deprecated regexp operand /JoeBloggs/"]); + warnings = collectLog(function() { + expect(wiki.filterTiddlers("[modifier/Jo/]").join(",")).toBe("TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one"); + }); + expect(warnings).toEqual(["WARNING: Filter modifier has a deprecated regexp operand /Jo/"]); }); it("should handle the prefix operator", function() {