Skip to content

Commit

Permalink
Merge pull request #65 from zazuko/filter-return-value
Browse files Browse the repository at this point in the history
fix: filter would return object with wrong context
  • Loading branch information
Thomas Bergwinkl authored Apr 4, 2022
2 parents dab663e + f98c8ae commit 075b5b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Clownface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/Clownface/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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(),
Expand Down

0 comments on commit 075b5b1

Please sign in to comment.