Blame SOURCES/test.js

58aaa5
'use strict';
58aaa5
/* eslint-env mocha */
58aaa5
var assert = require('assert');
58aaa5
58aaa5
Object.assign = undefined;
58aaa5
var objectAssign = require('./');
58aaa5
58aaa5
it('should have the correct length', function () {
58aaa5
	assert.equal(objectAssign.length, 2);
58aaa5
});
58aaa5
58aaa5
it('should throw when target is not an object', function () {
58aaa5
	assert.throws(function () {
58aaa5
		objectAssign(null);
58aaa5
	}, TypeError);
58aaa5
	assert.throws(function () {
58aaa5
		objectAssign(undefined);
58aaa5
	}, TypeError);
58aaa5
});
58aaa5
58aaa5
it('should objectAssign own enumerable properties from source to target object', function () {
58aaa5
	assert.deepEqual(objectAssign({foo: 0}, {bar: 1}), {
58aaa5
		foo: 0,
58aaa5
		bar: 1
58aaa5
	});
58aaa5
	assert.deepEqual(objectAssign({foo: 0}, null, undefined), {foo: 0});
58aaa5
	assert.deepEqual(objectAssign({foo: 0}, null, undefined, {bar: 1}, null), {
58aaa5
		foo: 0,
58aaa5
		bar: 1
58aaa5
	});
58aaa5
});
58aaa5
58aaa5
it('should throw on null/undefined target', function () {
58aaa5
	assert.throws(function () {
58aaa5
		objectAssign(null, {});
58aaa5
	});
58aaa5
58aaa5
	assert.throws(function () {
58aaa5
		objectAssign(undefined, {});
58aaa5
	});
58aaa5
58aaa5
	assert.throws(function () {
58aaa5
		objectAssign(undefined, undefined);
58aaa5
	});
58aaa5
});
58aaa5
58aaa5
it('should not throw on null/undefined sources', function () {
58aaa5
	assert.doesNotThrow(function () {
58aaa5
		objectAssign({}, null);
58aaa5
	});
58aaa5
58aaa5
	assert.doesNotThrow(function () {
58aaa5
		objectAssign({}, undefined);
58aaa5
	});
58aaa5
58aaa5
	assert.doesNotThrow(function () {
58aaa5
		objectAssign({}, undefined, null);
58aaa5
	});
58aaa5
});
58aaa5
58aaa5
it('should support multiple sources', function () {
58aaa5
	assert.deepEqual(objectAssign({foo: 0}, {bar: 1}, {bar: 2}), {
58aaa5
		foo: 0,
58aaa5
		bar: 2
58aaa5
	});
58aaa5
	assert.deepEqual(objectAssign({}, {}, {foo: 1}), {foo: 1});
58aaa5
});
58aaa5
58aaa5
it('should only iterate own keys', function () {
58aaa5
	var Unicorn = function () {};
58aaa5
	Unicorn.prototype.rainbows = 'many';
58aaa5
	var unicorn = new Unicorn();
58aaa5
	unicorn.bar = 1;
58aaa5
58aaa5
	assert.deepEqual(objectAssign({foo: 1}, unicorn), {
58aaa5
		foo: 1,
58aaa5
		bar: 1
58aaa5
	});
58aaa5
});
58aaa5
58aaa5
it('should return the modified target object', function () {
58aaa5
	var target = {};
58aaa5
	var returned = objectAssign(target, {a: 1});
58aaa5
	assert.equal(returned, target);
58aaa5
});
58aaa5
58aaa5
it('should support `Object.create(null)` objects', function () {
58aaa5
	var obj = Object.create(null);
58aaa5
	obj.foo = true;
58aaa5
	assert.deepEqual(objectAssign({}, obj), {foo: true});
58aaa5
});
58aaa5
58aaa5
it('should preserve property order', function () {
58aaa5
	var letters = 'abcdefghijklmnopqrst';
58aaa5
	var source = {};
58aaa5
	letters.split('').forEach(function (letter) {
58aaa5
		source[letter] = letter;
58aaa5
	});
58aaa5
	var target = objectAssign({}, source);
58aaa5
	assert.equal(Object.keys(target).join(''), letters);
58aaa5
});
58aaa5
58aaa5
it('should accept primitives as target', function () {
58aaa5
	var target = objectAssign('abcdefg', {foo: 'bar'});
58aaa5
	var strObj = Object('abcdefg');
58aaa5
	strObj.foo = 'bar';
58aaa5
	assert.deepEqual(target, strObj);
58aaa5
});
58aaa5
58aaa5
if (typeof Symbol !== 'undefined') {
58aaa5
	it('should support symbol properties', function () {
58aaa5
		var target = {};
58aaa5
		var source = {};
58aaa5
		var sym = Symbol('foo');
58aaa5
		source[sym] = 'bar';
58aaa5
		objectAssign(target, source);
58aaa5
		assert.equal(target[sym], 'bar');
58aaa5
	});
58aaa5
58aaa5
	it('should only copy enumerable symbols', function () {
58aaa5
		var target = {};
58aaa5
		var source = {};
58aaa5
		var sym = Symbol('foo');
58aaa5
		Object.defineProperty(source, sym, {
58aaa5
			enumerable: false,
58aaa5
			value: 'bar'
58aaa5
		});
58aaa5
		objectAssign(target, source);
58aaa5
		assert.equal(target[sym], undefined);
58aaa5
	});
58aaa5
}