使用 jasmine 进行测试时,出现此错误.
When testing using jasmine, I am getting this error.
TypeError:moment.tz 不是函数
我尝试测试的代码是
let myDate = moment().tz(undefined, vm.timeZone).format('YYYY-MM-DD');
如果您使用的是 Node.js,您可能会不小心使用
If you're using Node.js, you may accidentally be using
const moment = require('moment');//moment
而不是
const moment = require('moment-timezone');//moment-timezone
另外,请确保您已经安装了 moment-timezone
Also, make sure you have installed moment-timezone with
npm install moment-timezone --save
使用 require('moment') 安装 moment,然后决定 npm install moment-timezone,然后忘记更新 require.
The bug of requiring moment without timezones could occur by installing moment with require('moment'), later deciding to npm install moment-timezone, and then forgetting to update the require.
这篇关于TypeError: moment().tz 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 javascript 认为文档“准备好"之前,如何让How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 认为文档“准备好
jasmine 运行和等待实际上是做什么的?What do jasmine runs and waitsFor actually do?(jasmine 运行和等待实际上是做什么的?)
如何提供模拟文件来更改 <input type='filHow to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模拟文件来更改 lt;input type=filegt; 的事
如何使用 Jasmine 对链式方法进行单元测试How to unit test a chained method using Jasmine(如何使用 Jasmine 对链式方法进行单元测试)
如何将 $rootScope 注入 AngularJS 单元测试?How do I inject $rootScope into an AngularJS unit test?(如何将 $rootScope 注入 AngularJS 单元测试?)
Jasmine - 如何监视函数中的函数调用?Jasmine - How to spy on a function call within a function?(Jasmine - 如何监视函数中的函数调用?)