尝试测试时间格式。
utilities js file:
exports.getCurrentTime = function(s) {
var now = new Date();
var mins = lzero(now.getMinutes(), 2);
var dateTime = ' ' + now.getHours() + ':' + mins;
return dateTime;
};
规格类:
utilities_spec.js
require("/tijasmine/tijasmine").infect(this);
//create suite, which has a collection of functions for testing
// class or just a slew of functions.
describe("utilities", function() {
//import utilties class, so that we an access the functions.
var utilities = require('utilities');
it("Get current time", function() {
//matcher
expect(utilities.getCurrentTime()).toMatch('^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$');
});
收到以下错误:
utilities Get current time. - Expected ' 23:41' to match '^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$'.
如何成功传递正则表达式?如果我忽略正则表达式开头的引号,我会遇到编译器错误。
答案 0 :(得分:1)
我确定你真正想要的是/([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/
。
'([0-1]?[0-9]|2[0-3]):[0-5][0-9]$'
是一个普通字符串,而不是正则表达式。