Example #1
0
      it('should preserve the case of the first call', () => {
        const headers = new Headers();

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

        expect(headers.getAll('foo')).toEqual(['second']);
      });
Example #4
0
 it('should not alter the values of a provided header template', () => {
   // Spec at https://fetch.spec.whatwg.org/#concept-headers-fill
   // test for https://github.com/angular/angular/issues/6845
   const firstHeaders = new Headers();
   const secondHeaders = new Headers(firstHeaders);
   secondHeaders.append('Content-Type', 'image/jpeg');
   expect(firstHeaders.has('Content-Type')).toEqual(false);
 });
Example #5
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 Headers(httpHeaders);
   const secondHeadersObj = new Headers(secondHeaders);
   expect(secondHeadersObj.get('Content-Type')).toEqual('image/jpeg');
 });
Example #6
0
      it('should be case insensitive', () => {
        const headers = new Headers();

        headers.set('foo', 'baz');
        expect(headers.has('foo')).toEqual(true);
        headers.delete('foo');
        expect(headers.has('foo')).toEqual(false);

        headers.set('foo', 'baz');
        expect(headers.has('foo')).toEqual(true);
        headers.delete('FOO');
        expect(headers.has('foo')).toEqual(false);
      });
Example #7
0
 it('should preserve the list of values', () => {
   const src = new Headers();
   src.append('foo', 'a');
   src.append('foo', 'b');
   src.append('foo', 'c');
   const dst = new Headers(src);
   expect(dst.getAll('foo')).toEqual(src.getAll('foo'));
 });
Example #8
0
 it('should parse a response header string', () => {
   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 = Headers.fromResponseHeaderString(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 #9
0
      it('should clear all values and re-set for the provided key', () => {
        const headers = new Headers({'foo': 'bar'});
        expect(headers.get('foo')).toEqual('bar');

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

        headers.set('fOO', 'bat');
        expect(headers.get('foo')).toEqual('bat');
      });
Example #10
0
 it('should preserve cases after cloning', () => {
   const headers = new Headers();
   headers.set('fOo', 'baz');
   headers.set('foo', 'bat');
   expect(JSON.stringify(new Headers(headers))).toEqual('{"fOo":["bat"]}');
 });