基本上我有这个功能
// for each line in the csv
list($datePart, $timePart) = explode(' ', $fields['date']);
list($d, $m, $y) = explode('.', $datePart);
$dbDate = "$y-$m-$d $timePart";
我正在为此功能编写单元测试。这就是我到现在所写的。
function getDP() {
if (someFunctionOutsideAngular()) {
var str = vm.dp;
var selectedDate = '';
if (vm.dp == null) {
selectedDate = new Date();
} else {
selectedDate = vm.dp;
}
var options = {
date: selectedDate,
mode: 'date'
};
function onSuccess(date) {
vm.dt = new Date(date);
}
function onError(error) { // Android only
console.log('Error: ' + error);
}
datePicker.show(options, onSuccess, onError);
} else {
return false;
}
}
我被困在这里..我需要检查是否还有条件,成功和onError ..我已经声明了varialble ..并且如果我必须做(function(){
describe('test', function(){
var sut,
dataContext,
$q,
deferred,
$location;
beforeEach(module('app'));
beforeEach(inject(function(_$controller_, _dataContext_, _$q_,$location) {
inject(function($injector) {
sut = contFactory("mods", { $scope: $scope });
});
}));
describe('Definition tests', function(){
it('Should define the controller', function(){
expect(sut).toBeDefined();
});
var testCases = ['getDatePicker'];
_.forEach(testCases, function(testCase){
it(testCase + ' should be defined', function(){
expect(sut[testCase]).toBeDefined();
})
});
});
describe('and calling the getDatePicker function', function () {
it('and should define getDatePicker',function(){
expect(sut.getDatePicker).toBeDefined();
});
var lastCalibration;
it('return null lastCalibration', function(){
lastCalibration = sut.lastCalibration(null);
});
it('return true for lastCalibration', function(){
});
});
则会卡住。如何为这些写条件?