I am working with karma & jasmine for unit testing my javascript pages. After all configuration done i was able to run the test cases. However, the expect statement is falining stating undefined. even though i hard code 2 strings in the expect, its failing. I tried toBe & toEqual but without success. Below is my code:
describe('Sanity Test', function() {
var scope;
beforeEach(angular.mock.module('serviceApp'));
beforeEach(angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
$controller('welcomeController', {
$scope : scope
});
}));
it('Sanity test Jasmine"', function() {
scope.text = 'Hi';
expect('Hi').toEqual('Hi');
});
});
Error: INFO [launcher]: Starting browser Chrome INFO [Chrome 30.0.1599 (Windows 7)]: Connected on socket DjMqv6LulftBpkJ2ph7g Chrome 30.0.1599 (Windows 7) Sanity Test Sanity test Jasmine" FAILED expect undefined toEqual "Hi" .....src/main/webapp/test/spec/controllers/welcome.test.js:15:3: expected "Hi" but was undefined Chrome 30.0.1599 (Windows 7): Executed 1 of 1 (1 FAILED) ERROR (0.424 secs / 0.025 secs)
Been struggling for last 2 days.