You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.0 KiB

7 years ago
  1. var urljoin = require('../lib/url-join');
  2. describe('url join', function () {
  3. it('should work for simple case', function () {
  4. urljoin('http://www.google.com/', 'foo/bar', '?test=123')
  5. .should.eql('http://www.google.com/foo/bar?test=123');
  6. });
  7. it('should work for simple case with new syntax', function () {
  8. urljoin(['http://www.google.com/', 'foo/bar', '?test=123'])
  9. .should.eql('http://www.google.com/foo/bar?test=123');
  10. });
  11. it('should work for hashbang urls', function () {
  12. urljoin(['http://www.google.com', '#!', 'foo/bar', '?test=123'])
  13. .should.eql('http://www.google.com/#!/foo/bar?test=123');
  14. });
  15. it('should be able to join protocol', function () {
  16. urljoin('http:', 'www.google.com/', 'foo/bar', '?test=123')
  17. .should.eql('http://www.google.com/foo/bar?test=123');
  18. });
  19. it('should be able to join protocol with slashes', function () {
  20. urljoin('http://', 'www.google.com/', 'foo/bar', '?test=123')
  21. .should.eql('http://www.google.com/foo/bar?test=123');
  22. });
  23. it('should remove extra slashes', function () {
  24. urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123')
  25. .should.eql('http://www.google.com/foo/bar?test=123');
  26. });
  27. it('should support anchors in urls', function () {
  28. urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '#faaaaa')
  29. .should.eql('http://www.google.com/foo/bar?test=123#faaaaa');
  30. });
  31. it('should support protocol-relative urls', function () {
  32. urljoin('//www.google.com', 'foo/bar', '?test=123')
  33. .should.eql('//www.google.com/foo/bar?test=123')
  34. });
  35. it('should merge multiple query params properly', function () {
  36. urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456')
  37. .should.eql('http://www.google.com/foo/bar?test=123&key=456');
  38. urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?boom=value', '&key=456')
  39. .should.eql('http://www.google.com/foo/bar?test=123&boom=value&key=456');
  40. });
  41. });