【发布时间】:2017-10-14 19:01:45
【问题描述】:
我正在尝试将 Jasmine 与 moment.js 结合使用,但出现此错误...
debug.js:21 Uncaught TypeError: (0 , _moment.moment) is not a function
不确定它是否与 moment.js 相关,或者我是否设置不正确。感谢任何帮助。
//script.js
import { moment } from 'moment';
export class Age {
constructor(age, secondDate) {
this.age = age;
this.secondDate = secondDate;
}
getSecondsBetweenTwoDates(age, secondDate){
age = moment(this.age).format('l');
secondDate = moment(this.secondDate).format('l');
//differenceInSeconds = moment((this.secondDate).diff(this.age, 'days'));
differenceInDays = age.diff(secondDate, 'days');
//let differenceInDays = this.age - this.secondDate
return differenceInDays;
}
}
//age-spec.js
import { Age } from './../js/age.js';
describe('Age', function() {
let reusableDate,
today,
testDate = '2016-10-05',
date = '2016-10-10';
beforeEach(() => {
reusableDate = new Age(date, testDate);
console.log(reusableDate);
const mockedDateAndTime = '2017-03-02 00:00:00';
today = moment(mockedDateAndTime).toDate();
console.log('this is today', today);
jasmine.clock().mockDate(today);
});
it('should return the difference between today', () => {
console.log(date);
console.log(testDate);
console.log(reusableDate.getSecondsBetweenTwoDates(date, testDate));
console.log(typeof(reusableDate.getSecondsBetweenTwoDates));
//expect(5).toEqual(reusableDate.getSecondsBetweenTwoDates());
});
});
我根本没有使用 beforeEach 块,这只是我在 Google 上找到的东西,并且正在尝试......我还安装了一个 karma-moment 插件,如下所示:
框架:['jquery-3.2.1', 'jasmine', 'browserify', 'moment-2.9.0'],
插件:[ '业力 jquery', '业力浏览', '业力时刻', '业力茉莉', '业力铬发射器', '业力-茉莉花-html-记者' ]
【问题讨论】:
标签: unit-testing ecmascript-6 jasmine momentjs karma-jasmine