Example #1
0
 it('should append a value to the list', () => {
   const headers = new HttpHeaders();
   const second = headers.append('foo', 'bar');
   const third = second.append('foo', 'baz');
   expect(third.get('foo')).toEqual('bar');
   expect(third.getAll('foo')).toEqual(['bar', 'baz']);
 });
Example #2
0
      it('should keep the last value when initialized from an object', () => {
        const headers = new HttpHeaders({
          'foo': 'first',
          'fOo': 'second',
        });

        expect(headers.getAll('foo')).toEqual(['second']);
      });
Example #3
0
 it('should conform to spec', () => {
   const httpHeaders = {
     'Content-Type': 'image/jpeg',
     'Accept-Charset': 'utf-8',
     'X-My-Custom-Header': 'Zeke are cool',
   };
   const secondHeaders = new HttpHeaders(httpHeaders);
   expect(secondHeaders.get('Content-Type')).toEqual('image/jpeg');
 });
Example #4
0
      it('should clear all values and re-set for the provided key', () => {
        const headers = new HttpHeaders({'foo': 'bar'});
        expect(headers.get('foo')).toEqual('bar');

        const second = headers.set('foo', 'baz');
        expect(second.get('foo')).toEqual('baz');

        const third = headers.set('fOO', 'bat');
        expect(third.get('foo')).toEqual('bat');
      });
Example #5
0
 it('should lazily append values', () => {
   const src = new HttpHeaders();
   const a = src.append('foo', 'a');
   const b = a.append('foo', 'b');
   const c = b.append('foo', 'c');
   expect(src.getAll('foo')).toBeNull();
   expect(a.getAll('foo')).toEqual(['a']);
   expect(b.getAll('foo')).toEqual(['a', 'b']);
   expect(c.getAll('foo')).toEqual(['a', 'b', 'c']);
 });
Example #6
0
      it('should be case insensitive', () => {
        const headers = new HttpHeaders({'foo': 'baz'});
        expect(headers.has('foo')).toEqual(true);
        const second = headers.delete('foo');
        expect(second.has('foo')).toEqual(false);

        const third = second.set('foo', 'baz');
        expect(third.has('foo')).toEqual(true);
        const fourth = third.delete('FOO');
        expect(fourth.has('foo')).toEqual(false);
      });
Example #7
0
 it('should be parsed by the constructor', () => {
   const response = `Date: Fri, 20 Nov 2015 01:45:26 GMT\n` +
       `Content-Type: application/json; charset=utf-8\n` +
       `Transfer-Encoding: chunked\n` +
       `Connection: keep-alive`;
   const headers = new HttpHeaders(response);
   expect(headers.get('Date')).toEqual('Fri, 20 Nov 2015 01:45:26 GMT');
   expect(headers.get('Content-Type')).toEqual('application/json; charset=utf-8');
   expect(headers.get('Transfer-Encoding')).toEqual('chunked');
   expect(headers.get('Connection')).toEqual('keep-alive');
 });
Example #8
0
 it('should return null if the header is not present', () => {
   const headers = new HttpHeaders();
   expect(headers.getAll('foo')).toEqual(null);
 });
Example #9
0
 it('should be case insensitive', () => {
   const headers = new HttpHeaders({foo: ['bar', 'baz']});
   expect(headers.getAll('foo')).toEqual(['bar', 'baz']);
   expect(headers.getAll('FOO')).toEqual(['bar', 'baz']);
 });
Example #10
0
 it('should be case insensitive', () => {
   const headers = new HttpHeaders({'foo': 'baz'});
   expect(headers.get('foo')).toEqual('baz');
   expect(headers.get('FOO')).toEqual('baz');
 });