Skip to content

Commit

Permalink
Enable create tests and adapt it for the new primitive prototype beha…
Browse files Browse the repository at this point in the history
…vior (lodash#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
  • Loading branch information
blikblum authored and jdalton committed Aug 22, 2019
1 parent e5f8407 commit 9971765
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions test/create.js → test/create.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 9971765

Please sign in to comment.