UNPKG

1.01 kBJavaScriptView Raw
1import Proxy from 'http-proxy';
2import sinon from 'sinon';
3import {expect} from 'chai';
4
5import proxy from '../../../src/middleware/proxy';
6
7describe('proxy', () => {
8 let sandbox;
9 let server;
10
11 beforeEach(() => {
12 sandbox = sinon.sandbox.create();
13 sandbox.stub(Proxy, 'createProxy').returns(server = {
14 ws: sandbox.stub(),
15 web: sandbox.stub(),
16 });
17 });
18
19 afterEach(() => {
20 sandbox.restore();
21 });
22
23 it('shoud call the `web` proxy method on `request`', () => {
24 const spy = sinon.spy();
25 const options = { target: 'http://www.google.ca' };
26 const app = proxy(options)({ request: spy });
27 app.request(1, 2);
28 expect(server.web).to.be.calledWithMatch(1, 2, options);
29 });
30
31 it('shoud call the `ws` proxy method on `upgrade`', () => {
32 const spy = sinon.spy();
33 const options = { target: 'http://www.google.ca' };
34 const app = proxy(options)({ upgrade: spy });
35 app.upgrade(1, 2, 3);
36 expect(server.ws).to.be.calledWith(1, 2, 3, options);
37 });
38});