From f98c8aef8fbb1b3e67913eb6694bef01f84a72b2 Mon Sep 17 00:00:00 2001 From: tpluscode Date: Sat, 2 Apr 2022 20:31:46 +0200 Subject: [PATCH] fix: filter would return object with wrong context --- lib/Clownface.js | 2 +- test/Clownface/filter.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Clownface.js b/lib/Clownface.js index d579e1d..64001b1 100644 --- a/lib/Clownface.js +++ b/lib/Clownface.js @@ -200,7 +200,7 @@ class Clownface { filter (callback) { const pointers = this._context.map(context => Clownface.fromContext(context)) - return Clownface.fromContext(pointers.filter((pointer, index) => callback(pointer, index, pointers))) + return Clownface.fromContext(this._context.filter((context, index) => callback(Clownface.fromContext(context), index, pointers))) } /** diff --git a/test/Clownface/filter.js b/test/Clownface/filter.js index 908323a..d9c17c8 100644 --- a/test/Clownface/filter.js +++ b/test/Clownface/filter.js @@ -5,6 +5,7 @@ const clownface = require('../..') const loadExample = require('../support/example') const rdf = require('../support/factory') const Clownface = require('../../lib/Clownface') +const Context = require('../../lib/Context') describe('.filter', () => { it('should be a function', () => { @@ -19,6 +20,14 @@ describe('.filter', () => { assert(cf.filter(() => true) instanceof Clownface) }) + it('should return instance with _context of correct type', () => { + const cf = clownface({ dataset: rdf.dataset() }).namedNode() + + const [context] = cf.filter(() => true)._context + + assert(context instanceof Context) + }) + it('should call the function with Dataset parameter', async () => { const cf = clownface({ dataset: await loadExample(),