From 9971765d0c938ddb31d5035855262a5b9b1b4132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Thu, 22 Aug 2019 20:07:43 -0300 Subject: [PATCH] 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 --- test/{create.js => create.test.js} | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) rename test/{create.js => create.test.js} (69%) diff --git a/test/create.js b/test/create.test.js similarity index 69% rename from test/create.js rename to test/create.test.js index 4f287393ea..fef0be6de7 100644 --- a/test/create.js +++ b/test/create.test.js @@ -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() {