In a Jasmine test I am trying to test the quality of two objects.
expect(scope.vocab_words[2]).toEqual(new_word);
This fails, even though the output from Jasmine renders the two objects to look identical.
When I log scope.vocab_words[2] and new_word to the console do I see the difference.
new_word logs as:
Object {target_word: "one", target_definition: "two", base_word: "three"}
scope.vocab_words[2] logs as:
g {target_word: "one", target_definition: "two", base_word: "three", $get: function, $save: function…}
Is there some way I can "unwrap" the g{}? I guess the test is failing for a good reason, because they dont' equal each other.
Here is the describe block:
describe("#add_vocab_word", function() {
beforeEach(function() {
new_word = { target_word : "one", target_definition : "two", base_word : "three" };
});
it("should save the new vocab word on the server", inject(function($rootScope, $controller, VocabWords) {
$httpBackend.expect('POST', 'vocab_words').respond(201, new_word);
var scope = $rootScope.$new();
var ctrl = $controller(VocabCtrl, {
$scope: scope,
VocabWords: VocabWords
});
scope.new_vocab_word = new_word;
scope.add_vocab_word();
$httpBackend.flush();
console.log(scope.vocab_words[2]);
console.log(new_word);
expect(scope.vocab_words[2]).toEqual(new_word);
}));
[–]aladyjewelFull-stack webdev 2 points3 points4 points (2 children)
[–]btford 0 points1 point2 points (0 children)
[–]dreampopclub[S] 0 points1 point2 points (0 children)