From 82878ce14ea5d3e93476bfa30da1e2e2bfa683c7 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Mon, 8 Sep 2014 15:44:34 -0400 Subject: [PATCH] Test recursion into arrays --- test/fuse-test.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/fuse-test.js b/test/fuse-test.js index b8bde46..58f8730 100644 --- a/test/fuse-test.js +++ b/test/fuse-test.js @@ -339,4 +339,46 @@ vows.describe('Include both ID and score in results list').addBatch({ } } } -}).export(module); \ No newline at end of file +}).export(module); + +vows.describe('Recurse into arrays').addBatch({ + 'Options:': { + topic: function() { + var books = [{ + "ISBN": "0765348276", + "title": "Old Man's War", + "author": "John Scalzi", + "tags": ["fiction"] + }, { + "ISBN": "0312696957", + "title": "The Lock Artist", + "author": "Steve Hamilton", + "tags": ["fiction"] + }, { + "ISBN": "0321784421", + "title": "HTML5", + "author": "Remy Sharp", + "tags": ["nonfiction"] + }]; + var options = { + keys: ["tags"], + id: "ISBN", + threshold: 0 + } + var fuse = new Fuse(books, options) + return fuse; + }, + 'When searching for the tag "nonfiction"': { + topic: function(fuse) { + var result = fuse.search("nonfiction"); + return result; + }, + 'we get a list containing 1 item': function(result) { + assert.equal(result.length, 1); + }, + 'whose value is the ISBN of the book': function(result) { + assert.equal(result[0], '0321784421'); + } + } + } +}).export(module);