mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Refactored filter tests to use nifty spyOn method (#5550)
This commit is contained in:
parent
a6958bfe85
commit
427eb6d085
@ -14,22 +14,6 @@ Tests the filtering mechanism.
|
|||||||
/* global $tw, require */
|
/* global $tw, require */
|
||||||
"use strict";
|
"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() {
|
describe("Filter tests", function() {
|
||||||
|
|
||||||
// Test filter parsing
|
// 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 following 2 tests should write a log -> WARNING: Filter modifier has a deprecated regexp operand XXXX
|
||||||
// The test should pass anyway.
|
// The test should pass anyway.
|
||||||
it("should handle the field operator with a regular expression operand", function() {
|
it("should handle the field operator with a regular expression operand", function() {
|
||||||
var warnings = collectLog(function() {
|
spyOn(console, 'log');
|
||||||
expect(wiki.filterTiddlers("[modifier/JoeBloggs/]").join(",")).toBe("TiddlerOne");
|
expect(wiki.filterTiddlers("[modifier/JoeBloggs/]").join(",")).toBe("TiddlerOne");
|
||||||
});
|
expect(console.log).toHaveBeenCalledWith("WARNING: Filter", "modifier", "has a deprecated regexp operand", /JoeBloggs/);
|
||||||
expect(warnings).toEqual(["WARNING: Filter modifier has a deprecated regexp operand /JoeBloggs/"]);
|
console.log.calls.reset();
|
||||||
warnings = collectLog(function() {
|
|
||||||
expect(wiki.filterTiddlers("[modifier/Jo/]").join(",")).toBe("TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one");
|
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/);
|
||||||
expect(warnings).toEqual(["WARNING: Filter modifier has a deprecated regexp operand /Jo/"]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle the prefix operator", function() {
|
it("should handle the prefix operator", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user