Skip to content

Instantly share code, notes, and snippets.

@softcraft-development
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softcraft-development/1c3964402b099893bd61 to your computer and use it in GitHub Desktop.
Save softcraft-development/1c3964402b099893bd61 to your computer and use it in GitHub Desktop.
Testing _.extend() for underscore/lodash
describe "Underscore Extend", ->
describe "simple objects", ->
it "bequeaths properties", ->
obj =
prop: "value"
expect(_.extend({}, obj).prop).toEqual("value")
it "bequeaths methods", ->
obj =
meth: () ->
"value"
expect(_.extend({}, obj).meth()).toEqual("value")
describe "defined classes", ->
class Ancestor
prop: "prop value"
constructor: () ->
@var = "var value"
meth: () ->
"meth value"
it "bequeaths properties", ->
# Fails in non-underscore lodash
expect(_.extend({}, new Ancestor()).prop).toEqual("prop value")
it "bequeaths variables", ->
expect(_.extend({}, new Ancestor()).var).toEqual("var value")
it "bequeaths instances", ->
# Fails in non-underscore lodash
expect(_.extend({}, new Ancestor()).meth?()).toEqual("meth value")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment