在我的角度应用程序中,我正在尝试使用momentjs对某些内容进行单元测试。
运行测试时,我不断获得TypeError: moment(...).locale(...).format is not a function
我确实试过https://www.npmjs.com/package/karma-moment
但遗憾的是没有任何区别。
任何想法如何在我的moment
单元测试中使用karma
。
karma.conf.js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli', 'moment-2.9.0'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-phantomjs-launcher'),
require('karma-moment'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browserNoActivityTimeout: 50000,
browsers: ['PhantomJS'],
singleRun: false
});
};
我有pipe
使用momentjs
:
import * as moment from "moment";
@Pipe({
name: 'dateText'
})
export class DateTextPipe implements PipeTransform {
...
transform(value) {
return moment(value).format('LL')
}
}