我正在编写一个钩子,当用户执行操作时,该钩子将日志写入DB。我想确保它能按预期工作。因此,我尝试为此编写测试。这就是我想要的。
// eslint-disable-next-line no-unused-vars
module.exports = ({ name }) => {
return async context => {
const service = context.app.service('tasks');
const id = context.id;
const action = context.data.status;
let { log } = await service.get(id);
const status = `The task was ${action} on ${Date()} by jdoe#10000`;
log.push(status);
context.data.log = log;
return context;
};
};
到目前为止,这是我要进行的测试。但我不确定下一步是什么
const assert = require('assert');
const feathers = require('@feathersjs/feathers');
const updateStatus = require('../../src/hooks/updatestatus-task.js');
describe('\'updateStatus\' hook', () => {
let app;
beforeEach(() => {
app = feathers();
app.use('/dummy', {
async create(data) {
return data ;
}
});
app.service('dummy').hooks({
before: updateStatus({name: 'taskLog', action: 'Approved'})
});
assert.ok(app.service('dummy'));
});