mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Enable create tests and adapt it for the new primitive prototype behavior (#4418)
* Enable create tests and adapt it for the new primitive prototype behavior * Use isObject in create tests instead of manual check * Store properties in a variable when used more than once in create tests * Add parens around arrow function params in create tests
This commit is contained in:
committed by
John-David Dalton
parent
e5f840745b
commit
9971765d0c
@@ -1,6 +1,6 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { falsey, stubObject, primitives, stubTrue } from './utils.js';
|
||||
import { falsey, primitives, stubTrue } from './utils.js';
|
||||
import create from '../create.js';
|
||||
import keys from '../keys.js';
|
||||
|
||||
@@ -27,13 +27,17 @@ describe('create', function() {
|
||||
|
||||
it('should assign `properties` to the created object', function() {
|
||||
var expected = { 'constructor': Circle, 'radius': 0 };
|
||||
var properties = Object.keys(expected);
|
||||
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);
|
||||
assert.deepStrictEqual(Object.keys(Circle.prototype), properties);
|
||||
properties.forEach((property) => {
|
||||
assert.strictEqual(Circle.prototype[property], expected[property]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should assign own properties', function() {
|
||||
@@ -43,7 +47,14 @@ describe('create', function() {
|
||||
}
|
||||
Foo.prototype.b = 2;
|
||||
|
||||
assert.deepStrictEqual(create({}, new Foo), { 'a': 1, 'c': 3 });
|
||||
var actual = create({}, new Foo);
|
||||
var expected = { 'a': 1, 'c': 3 };
|
||||
var properties = Object.keys(expected);
|
||||
|
||||
assert.deepStrictEqual(Object.keys(actual), properties);
|
||||
properties.forEach((property) => {
|
||||
assert.strictEqual(actual[property], expected[property]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should assign properties that shadow those of `prototype`', function() {
|
||||
@@ -55,23 +66,23 @@ describe('create', function() {
|
||||
});
|
||||
|
||||
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);
|
||||
actual.forEach((value) => {
|
||||
assert.ok(lodashStable.isObject(value));
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore a primitive `prototype` and use an empty object instead', function() {
|
||||
var expected = lodashStable.map(primitives, stubTrue);
|
||||
|
||||
it('should accept a primitive `prototype`', function() {
|
||||
var actual = lodashStable.map(primitives, function(value, index) {
|
||||
return lodashStable.isPlainObject(index ? create(value) : create());
|
||||
return index ? create(value) : create();
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
actual.forEach((value) => {
|
||||
assert.ok(lodashStable.isObject(value));
|
||||
});
|
||||
});
|
||||
|
||||
it('should work as an iteratee for methods like `_.map`', function() {
|
||||
Reference in New Issue
Block a user