mercredi 28 janvier 2015

How to solve my unit test issue in my case

I am trying to write a unit test for my codes and I need some guidance.


I have something in my file like



//inside my 'testCtrl' I have
$scope.calculateTime = function() {
var date = new Date();
$scope.currentYear = date.getFullYear();
}

$scope.calculateLastYear = function() {
$scope.currentYear = $scope.currentYear - 1;
}


my test file.



describe('Controller: testCtrl', function(){
beforeEach(module('myApp'));
beforeEach(inject(function(_$controller_, _$rootscope_) {
scope._$rootScope.$new();

testCtrl = _$controller_('testCtrl', {
$scope:scope
})
})

//for some reason, every tests I write below are passed even
//though it should fail

it('should get the last year'), function() {
expect(scope.currentYear).toBe('text here….') //<-- it should fail but
//it passes
};
})


I am not sure how to write the test to check the calculateLastYear function and I don't know why my expect(scope.currentYear).toBe('text here….') passed. Can anyone help me about it? Thanks a lot!


Aucun commentaire:

Enregistrer un commentaire