我嘗試茉莉花與moment.js一起選擇,但我得到這個錯誤...收到錯誤moment.moment是不是一個函數,使用茉莉花和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塊可言,那只是東西,我在谷歌找到,並試圖...我還安裝了卡瑪時刻插件像這樣:
框架:[ '的jquery-3.2.1', '茉莉', 'browserify', '瞬間-2.9.0'],
插件:[ '果報的jquery', 「karma- browserify', '卡瑪時刻', '果報茉莉花', '因果報應 - 鉻 - 發射', 「因果報應 - 茉莉HTML-記者 ]
感謝您的回答,我不知道這一點。 – Lucky500