From 427eb6d08511009f6ee09145f8f2268d90328f35 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Thu, 18 Mar 2021 04:57:21 -0400 Subject: [PATCH] Refactored filter tests to use nifty spyOn method (#5550) --- editions/test/tiddlers/tests/test-filters.js | 30 ++++---------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index a820c4d04..b67a2d298 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -14,22 +14,6 @@ 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 @@ -265,14 +249,12 @@ 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() { - 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/"]); + spyOn(console, 'log'); + expect(wiki.filterTiddlers("[modifier/JoeBloggs/]").join(",")).toBe("TiddlerOne"); + expect(console.log).toHaveBeenCalledWith("WARNING: Filter", "modifier", "has a deprecated regexp operand", /JoeBloggs/); + console.log.calls.reset(); + expect(wiki.filterTiddlers("[modifier/Jo/]").join(",")).toBe("TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one"); + expect(console.log).toHaveBeenCalledWith("WARNING: Filter", "modifier", "has a deprecated regexp operand", /Jo/); }); it("should handle the prefix operator", function() {