mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { falsey, stubObject, primitives, stubTrue } from './utils.js';
|
|
import create from '../create.js';
|
|
import keys from '../keys.js';
|
|
|
|
describe('create', function() {
|
|
function Shape() {
|
|
this.x = 0;
|
|
this.y = 0;
|
|
}
|
|
|
|
function Circle() {
|
|
Shape.call(this);
|
|
}
|
|
|
|
it('should create an object that inherits from the given `prototype` object', function() {
|
|
Circle.prototype = create(Shape.prototype);
|
|
Circle.prototype.constructor = Circle;
|
|
|
|
var actual = new Circle;
|
|
|
|
assert.ok(actual instanceof Circle);
|
|
assert.ok(actual instanceof Shape);
|
|
assert.notStrictEqual(Circle.prototype, Shape.prototype);
|
|
});
|
|
|
|
it('should assign `properties` to the created object', function() {
|
|
var expected = { 'constructor': Circle, 'radius': 0 };
|
|
Circle.prototype = create(Shape.prototype, expected);
|
|
|
|
var actual = new Circle;
|
|
|
|
assert.ok(actual instanceof Circle);
|
|
assert.ok(actual instanceof Shape);
|
|
assert.deepStrictEqual(Circle.prototype, expected);
|
|
});
|
|
|
|
it('should assign own properties', function() {
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.c = 3;
|
|
}
|
|
Foo.prototype.b = 2;
|
|
|
|
assert.deepStrictEqual(create({}, new Foo), { 'a': 1, 'c': 3 });
|
|
});
|
|
|
|
it('should assign properties that shadow those of `prototype`', function() {
|
|
function Foo() {
|
|
this.a = 1;
|
|
}
|
|
var object = create(new Foo, { 'a': 1 });
|
|
assert.deepStrictEqual(lodashStable.keys(object), ['a']);
|
|
});
|
|
|
|
it('should accept a falsey `prototype`', function() {
|
|
var expected = lodashStable.map(falsey, stubObject);
|
|
|
|
var actual = lodashStable.map(falsey, function(prototype, index) {
|
|
return index ? create(prototype) : create();
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should ignore a primitive `prototype` and use an empty object instead', function() {
|
|
var expected = lodashStable.map(primitives, stubTrue);
|
|
|
|
var actual = lodashStable.map(primitives, function(value, index) {
|
|
return lodashStable.isPlainObject(index ? create(value) : create());
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should work as an iteratee for methods like `_.map`', function() {
|
|
var array = [{ 'a': 1 }, { 'a': 1 }, { 'a': 1 }],
|
|
expected = lodashStable.map(array, stubTrue),
|
|
objects = lodashStable.map(array, create);
|
|
|
|
var actual = lodashStable.map(objects, function(object) {
|
|
return object.a === 1 && !keys(object).length;
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
});
|