koa-lite/test/request/subdomains.js
Adam Lau b1a14f1a73 fix: subdomains should be [] if the host is an ip (#807)
* fix: subdomains should be [] if the host is an ip

Fixes #775
2016-09-07 11:23:39 +08:00

27 lines
677 B
JavaScript

'use strict';
var request = require('../context').request;
describe('req.subdomains', function(){
it('should return subdomain array', function(){
var req = request();
req.header.host = 'tobi.ferrets.example.com';
req.app.subdomainOffset = 2;
req.subdomains.should.eql(['ferrets', 'tobi']);
req.app.subdomainOffset = 3;
req.subdomains.should.eql(['tobi']);
})
it('should work with no host present', function(){
var req = request();
req.subdomains.should.eql([]);
})
it('should check if the host is an ip address', function(){
var req = request();
req.header.host = '127.0.0.1';
req.subdomains.should.eql([]);
});
})