Files
react-native/Libraries/Blob/__tests__/File-test.js
T
James Ide 0ee5f68929 Migrate "Libraries" from Haste to standard path-based requires (sans vendor & renderers) (#24749)
Summary:
This is the next step in moving RN towards standard path-based requires. All the requires in `Libraries` have been rewritten to use relative requires with a few exceptions, namely, `vendor` and `Renderer/oss` since those need to be changed upstream. This commit uses relative requires instead of `react-native/...` so that if Facebook were to stop syncing out certain folders and therefore remove code from the react-native package, internal code at Facebook would not need to change.

See the umbrella issue at https://github.com/facebook/react-native/issues/24316 for more detail.

[General] [Changed] - Migrate "Libraries" from Haste to standard path-based requires
Pull Request resolved: https://github.com/facebook/react-native/pull/24749

Differential Revision: D15258017

Pulled By: cpojer

fbshipit-source-id: a1f480ea36c05c659b6f37c8f02f6f9216d5a323
2019-05-08 08:48:59 -07:00

76 lines
2.1 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+react_native
*/
'use strict';
jest.setMock('../../BatchedBridge/NativeModules', {
BlobModule: require('../__mocks__/BlobModule'),
});
const Blob = require('../Blob');
const File = require('../File');
describe('babel 7 smoke test', function() {
it('should be able to extend a class with native name', function() {
let called = false;
class Array {
constructor() {
called = true;
return {foo: 'PASS'};
}
}
class A extends Array {
constructor() {
super();
}
}
// there is/was a regression in Babel where this would break and super()
// would not actually invoke the constructor of the parent class if the
// parent class had a name matching a built-in class (like Blob)
expect(new A().foo).toBe('PASS');
expect(called).toBe(true);
});
});
describe('Blob', function() {
it('regression caused by circular dep && babel 7', function() {
const blob = new Blob([], {type: 'image/jpeg'});
expect(blob).toBeInstanceOf(Blob);
});
});
describe('File', function() {
it('should create empty file', () => {
const file = new File([], 'test.jpg');
expect(file).toBeInstanceOf(File);
expect(file.data.offset).toBe(0);
expect(file.data.size).toBe(0);
expect(file.size).toBe(0);
expect(file.type).toBe('');
expect(file.name).toBe('test.jpg');
expect(file.lastModified).toEqual(expect.any(Number));
});
it('should create empty file with type', () => {
const file = new File([], 'test.jpg', {type: 'image/jpeg'});
expect(file.type).toBe('image/jpeg');
});
it('should create empty file with lastModified', () => {
const file = new File([], 'test.jpg', {lastModified: 1337});
expect(file.lastModified).toBe(1337);
});
it('should throw on invalid arguments', () => {
expect(() => new File()).toThrow();
expect(() => new File([])).toThrow();
});
});