mirror of
https://github.com/feathersjs/feathers.git
synced 2026-02-01 17:37:38 +00:00
Add breaking test (#931)
* add breaking test * fix bug by replacing makeArguments
This commit is contained in:
parent
1c066c76a1
commit
489792bbad
@ -6,10 +6,14 @@ const {
|
||||
getHooks,
|
||||
processHooks,
|
||||
enableHooks,
|
||||
makeArguments,
|
||||
ACTIVATE_HOOKS
|
||||
} = hooks;
|
||||
|
||||
const makeArguments = (service, method, hookObject) => service.methods[ method ].reduce((result, value) => ([
|
||||
...result,
|
||||
hookObject[ value ]
|
||||
]), []);
|
||||
|
||||
const withHooks = function withHooks ({
|
||||
app,
|
||||
service,
|
||||
@ -49,7 +53,7 @@ const withHooks = function withHooks ({
|
||||
}
|
||||
|
||||
// Otherwise, call it with arguments created from the hook object
|
||||
const promise = _super(...makeArguments(hookObject));
|
||||
const promise = _super(...makeArguments(service, method, hookObject));
|
||||
|
||||
if (!isPromise(promise)) {
|
||||
throw new Error(`Service method '${hookObject.method}' for '${hookObject.path}' service must return a promise`);
|
||||
|
||||
@ -312,4 +312,34 @@ describe('hooks basics', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('context.data should not change arguments', () => {
|
||||
const app = feathers().use('/dummy', {
|
||||
methods: {
|
||||
custom: ['id', 'params']
|
||||
},
|
||||
get () {},
|
||||
custom (id, params) {
|
||||
return Promise.resolve([id, params]);
|
||||
}
|
||||
});
|
||||
|
||||
app.service('dummy').hooks({
|
||||
before: {
|
||||
all (context) {
|
||||
context.test = ['all::before'];
|
||||
},
|
||||
custom (context) {
|
||||
context.data = { post: 'title' };
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const args = [1, { provider: 'rest' }];
|
||||
|
||||
return app.service('dummy').custom(...args)
|
||||
.then(result => {
|
||||
assert.deepEqual(result, args);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user