Utils.spec.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { assert } from 'chai';
  2. import { Utils } from '../../../src/utils/Utils';
  3. describe('Utils', () => {
  4. describe('extractDomainFrom', () => {
  5. describe('Variant #1: simple url', () => {
  6. const url: string = 'http://google.ru';
  7. const expectedDomain: string = 'google.ru';
  8. let domain: string;
  9. before(() => {
  10. domain = Utils.extractDomainFrom(url);
  11. });
  12. it('should extract domain from the given URL', () => {
  13. assert.equal(domain, expectedDomain);
  14. });
  15. });
  16. describe('Variant #2: url with `www` part', () => {
  17. const url: string = 'http://www.google.ru';
  18. const expectedDomain: string = 'www.google.ru';
  19. let domain: string;
  20. before(() => {
  21. domain = Utils.extractDomainFrom(url);
  22. });
  23. it('should extract domain from the given URL', () => {
  24. assert.equal(domain, expectedDomain);
  25. });
  26. });
  27. describe('Variant #3: url with `https` protocol and port', () => {
  28. const url: string = 'https://www.google.ru:9000';
  29. const expectedDomain: string = 'www.google.ru';
  30. let domain: string;
  31. before(() => {
  32. domain = Utils.extractDomainFrom(url);
  33. });
  34. it('should extract domain from the given URL', () => {
  35. assert.equal(domain, expectedDomain);
  36. });
  37. });
  38. describe('Variant #4: protocol-wide url and route', () => {
  39. const url: string = '//google.ru/abc';
  40. const expectedDomain: string = 'google.ru';
  41. let domain: string;
  42. before(() => {
  43. domain = Utils.extractDomainFrom(url);
  44. });
  45. it('should extract domain from the given URL', () => {
  46. assert.equal(domain, expectedDomain);
  47. });
  48. });
  49. describe('Variant #5: protocol-wide url, `localhost` and port', () => {
  50. const url: string = '//localhost:9000';
  51. const expectedDomain: string = 'localhost';
  52. let domain: string;
  53. before(() => {
  54. domain = Utils.extractDomainFrom(url);
  55. });
  56. it('should extract domain from the given URL', () => {
  57. assert.equal(domain, expectedDomain);
  58. });
  59. });
  60. });
  61. });