Skip to content

Commit

Permalink
add test assertion to ensure context internals are not overridden by …
Browse files Browse the repository at this point in the history
…plugins
  • Loading branch information
nikrowell committed Feb 12, 2020
1 parent f106e3c commit bcef026
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function picoapp (components = {}, initialState = {}, plugins = []) {

try {
const ext = plugins.reduce((res, fn) => {
const obj = fn(node)
const obj = fn(node, evx)
return isObj(obj) ? Object.assign(res, obj) : res
}, {})
const instance = comp(node, {...ext, ...evx})
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,23 @@ test('unmount', t => {
app.emit('foo')
})
test('plugins', t => {
t.plan(2)

function testContext(ctx) {
const internals = ['getState', 'hydrate', 'on', 'emit']
const preserved = internals.every(key => typeof ctx[key] === 'function')
t.true(preserved)
}

const app = picoapp({
foo: component((node, ctx) => {
t.true(ctx.props.hello === 'World')
testContext(ctx);
})
})

app.use((node, ctx) => ({
getState: undefined,
props: JSON.parse(node.dataset.props || '{}')
}))

Expand Down

0 comments on commit bcef026

Please sign in to comment.