UNPKG

799 BJavaScriptView Raw
1import { expect } from 'chai';
2import sinon from 'sinon';
3
4import thunk from '../../../src/middleware/thunk';
5
6describe('thunk', () => {
7 it('should use the result of the thunk', () => {
8 const next = sinon.spy();
9 const stub = sinon.spy((app) => () => {
10 return {
11 ...app,
12 request(req, res) {
13 app.request(req, res);
14 },
15 };
16 });
17 const app = thunk(stub)({ request: next });
18 const req = 1;
19 const res = 2;
20 app.request(req, res);
21 expect(stub).to.be.calledOnce;
22 });
23
24 it('should not wrap non-functions', () => {
25 const next = sinon.spy();
26 const stub = sinon.spy((app) => {
27 return () => app;
28 });
29 const app = thunk(stub)({ request: next, foo: null });
30 expect(app).to.have.property('foo', null);
31 });
32});