mirror of
https://github.com/186526/handlers.js
synced 2024-10-13 00:29:43 +00:00
release: 0.1.2
This commit is contained in:
@ -59,4 +59,25 @@ describe('Test server', () => {
|
||||
expect(status).toEqual(200);
|
||||
expect(data).toEqual('hit');
|
||||
});
|
||||
|
||||
test('dynamic handler', async () => {
|
||||
expect.assertions(6);
|
||||
|
||||
const { status: firstStatus, data: firstData } = await Instance.get(
|
||||
`/handler`,
|
||||
);
|
||||
|
||||
const { data, status } = await Instance.get(`/handler/add`);
|
||||
|
||||
const { status: secondStatus, data: secondData } = await Instance.get(
|
||||
`/handler`,
|
||||
);
|
||||
|
||||
expect(firstStatus).toEqual(200);
|
||||
expect(firstData).toEqual('miss');
|
||||
expect(status).toEqual(200);
|
||||
expect(data).toEqual('added');
|
||||
expect(secondStatus).toEqual(200);
|
||||
expect(secondData).toEqual('hit');
|
||||
});
|
||||
});
|
||||
|
||||
@ -7,6 +7,20 @@ App.binding(
|
||||
App.create('GET', async () => '200 OK'),
|
||||
);
|
||||
|
||||
const dynamicHandler = new handlersJS.handler('GET', [
|
||||
async () => new handlersJS.response('miss'),
|
||||
]);
|
||||
|
||||
App.binding('/handler', dynamicHandler);
|
||||
|
||||
App.binding(
|
||||
'/handler/add',
|
||||
App.create('GET', async () => {
|
||||
dynamicHandler.add(async () => new handlersJS.response('hit'));
|
||||
return 'added';
|
||||
}),
|
||||
);
|
||||
|
||||
App.binding(
|
||||
'/post',
|
||||
App.create(
|
||||
|
||||
Reference in New Issue
Block a user