Skip to content

Commit

Permalink
Implemented lodash mixin to handle the case where the undefined value…
Browse files Browse the repository at this point in the history
…s were being tested against
  • Loading branch information
zakhenry committed Aug 10, 2015
1 parent 8e94128 commit 56671db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
37 changes: 37 additions & 0 deletions app/src/common/libs/lodash_mixins.ts
@@ -0,0 +1,37 @@
declare module _ {
interface LoDashStatic {
compactObject<T>(object:T, removeFunctions?:boolean):T;
}
}

namespace common.libs {

/**
* lodash_mixins.ts
* Add mixins (additional functions) to lodash. Call them with _.[fn_name](params)
* See http://lodash.com/docs#mixin for more info
*/

_.mixin({

/**
* Get an object with all falsy values removed
* @returns {Object}
* @param object
* @param removeFunctions
*/
compactObject : (object:Object, removeFunctions:boolean = false):Object => {
var clone = _.clone(object);
_.each(clone, function(value, key) {
if(!value || removeFunctions && _.isFunction(value)) {
delete clone[key];
}
});
return clone;
}


});


}
3 changes: 1 addition & 2 deletions app/src/common/services/user/userService.spec.ts
Expand Up @@ -124,10 +124,9 @@

it('should be able to create a new user and attempt login immediately', () => {

let user = _.clone(fixtures.user);
let user = _.compactObject(fixtures.user);
delete user._self;


$httpBackend.expectPUT(/\/api\/users\/.+/, (requestObj) => {
return _.isEqual(_.keys(user), _.keys(JSON.parse(requestObj))); //as we are not aware of what the userId or userCredentialId is we cannot test full equality
}).respond(204);
Expand Down

0 comments on commit 56671db

Please sign in to comment.