var expect = require('expect') var utils = require('../lib/utils') var assign = utils.assign var forEach = utils.forEach var isArray = utils.isArray var isFunction = utils.isFunction var isRegExp = utils.isRegExp var isString = utils.isString var noop = utils.noop function SomeClass (foo) { this.foo = foo } SomeClass.prototype.bar = 'asdf' describe('utils', function () { it('→ exists', function () { expect(utils).toBeDefined() }) describe('→ noop', function () { it('→ is a function', function () { expect(noop).toBeInstanceOf(Function) }) }) describe('→ isString', function () { it('→ true for strings', function () { expect(isString('is string')).toBe(true) }) it('→ false for not strings', function () { expect(isString(/is string/)).toBe(false) }) }) describe('→ isRegExp', function () { it('→ true for regex', function () { expect(isRegExp(/some regex/)).toBe(true) }) it('→ false for strings', function () { expect(isRegExp('some string')).toBe(false) }) }) describe('→ isArray', function () { it('→ true for array', function () { expect(isArray([])).toBe(true) }) it('→ false for regex', function () { expect(isArray(/some regex/)).toBe(false) }) it('→ false for strings', function () { expect(isArray('some string')).toBe(false) }) }) describe('→ isFunction', function () { it('→ true for function', function () { expect(isFunction(function () {})).toBe(true) }) it('→ false for array', function () { expect(isFunction([])).toBe(false) }) it('→ false for regex', function () { expect(isFunction(/some regex/)).toBe(false) }) it('→ false for strings', function () { expect(isFunction('some string')).toBe(false) }) }) describe('→ forEach', function () { it('→ does not call properties on prototype', function () { var count = 0 forEach(new SomeClass(123), function (key, value) { count += 1 expect(key).toBe('foo') expect(value).toBe(123) }) expect(count).toEqual(1) }) }) describe('→ assign', function () { it('→ adds properties to dest', function () { var dest = {} var src = {foo: 123, bar: 'asdf'} assign(dest, src) expect(dest).toEqual({foo: 123, bar: 'asdf'}) }) it('→ overrides properties to dest', function () { var dest = {foo: 456, bar: 'qwerty', blah: /foo/} var src = {foo: 123, bar: 'asdf'} assign(dest, src) expect(dest).toEqual({foo: 123, bar: 'asdf', blah: /foo/}) }) it('→ does not overrides properties on prototype', function () { var dest = {foo: 456, bar: 'qwerty', blah: /foo/} assign(dest, new SomeClass(123)) expect(dest).toEqual({foo: 123, bar: 'qwerty', blah: /foo/}) }) }) })