2017-02-10 21:26:14 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-11-02 13:14:11 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2017-11-02 13:14:11 +00:00
|
|
|
* @emails oncall+react_native
|
2017-02-10 21:26:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const FormData = require('FormData');
|
|
|
|
|
|
|
|
describe('FormData', function() {
|
|
|
|
var formData;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
formData = new FormData();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
formData = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return non blob null', function() {
|
|
|
|
formData.append('null', null);
|
|
|
|
|
|
|
|
const expectedPart = {
|
|
|
|
string: 'null',
|
|
|
|
headers: {
|
2018-05-11 02:06:46 +00:00
|
|
|
'content-disposition': 'form-data; name="null"',
|
2017-02-10 21:26:14 +00:00
|
|
|
},
|
2018-05-11 02:06:46 +00:00
|
|
|
fieldName: 'null',
|
2017-02-10 21:26:14 +00:00
|
|
|
};
|
|
|
|
expect(formData.getParts()[0]).toMatchObject(expectedPart);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return blob', function() {
|
|
|
|
formData.append('photo', {
|
|
|
|
uri: 'arbitrary/path',
|
|
|
|
type: 'image/jpeg',
|
2018-05-11 02:06:46 +00:00
|
|
|
name: 'photo.jpg',
|
2017-02-10 21:26:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const expectedPart = {
|
|
|
|
uri: 'arbitrary/path',
|
|
|
|
type: 'image/jpeg',
|
|
|
|
name: 'photo.jpg',
|
|
|
|
headers: {
|
|
|
|
'content-disposition': 'form-data; name="photo"; filename="photo.jpg"',
|
2018-05-11 02:06:46 +00:00
|
|
|
'content-type': 'image/jpeg',
|
2017-02-10 21:26:14 +00:00
|
|
|
},
|
2018-05-11 02:06:46 +00:00
|
|
|
fieldName: 'photo',
|
2017-02-10 21:26:14 +00:00
|
|
|
};
|
|
|
|
expect(formData.getParts()[0]).toMatchObject(expectedPart);
|
|
|
|
});
|
|
|
|
});
|