I am building directory tests in Angular using Jasmine. I have a small test example that looks like this:
it("should compare html node", inject( function ($compile, $rootScope) { var elm = angular.element('<input>'); elm = $compile(elm)($scope); $scope.$digest(); console.log('btn', elm); // output: '<input class="ng-scope">' expect(elm).toBe('<input class="ng-scope">'); expect(elm[0]).toBe('<input class="ng-scope">'); // these also fail expect(elm.html()).toBe('<input class="ng-scope">'); // "" }));
So, I get the expected output to the console, but Jasmine complains about the error Expected { length: 1, 0: HTMLNode } to be '<input class="ng-scope">'
I also tried using elm[0] , which gives the same error and elm.html() , but that just returns an empty string. How can I compare HTML Node with string correctly?
NB I know this is an unrealistic test, but I just want to demonstrate my current problem.
angularjs angularjs-directive jasmine
Darwin tech
source share