Skip to content

Commit 4711344

Browse files
committed
Add tests
1 parent 4cd8013 commit 4711344

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,29 @@ describe('CORS middleware', () => {
205205
});
206206

207207

208+
it('should pass through OPTIONS requests if no Origin header was set', async () => {
209+
210+
const options = {
211+
allowOrigin: ['https://example.org'],
212+
allowHeaders: ['Content-Type', 'Accept'],
213+
allowMethods: ['GET', 'POST'],
214+
exposeHeaders: ['Link', 'Date']
215+
};
216+
const headers = {};
217+
const app = new Application;
218+
app.use(cors(options));
219+
220+
app.use( ctx => {
221+
222+
ctx.status = 200;
223+
ctx.response.body = ctx.method;
224+
225+
});
226+
227+
const response = await app.subRequest('OPTIONS', '/', headers);
228+
expect(response.status).to.equal(200);
229+
expect(response.body).to.equal('OPTIONS');
230+
231+
});
208232

209233
});

0 commit comments

Comments
 (0)