Angular2+

编程入门 行业动态 更新时间:2024-10-28 03:30:08
本文介绍了Angular2+ - 类型错误:form.reset 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

这是从继承的问题查找 [object ErrorEvent] 被抛出的位置和原因,这是对不同问题进行故障排除的结果.

This is a question carried over from Finding where and why [object ErrorEvent] is being thrown as a result of troubleshooting a different problem.

我正在模拟一个 NgForm 以传递到我的登录屏幕测试中,但是在传递不正确的详细信息时,我正在使用 form.reset() 来重置整个事情.

I am mocking an NgForm to pass into my test for a login screen, however upon passing in incorrect details I am using form.reset() to reset the whole thing.

我在 Jasmine 中收到错误 TypeError: form.reset is not a function

I get the error TypeError: form.reset is not a function in my Jasmine

我被告知我的模拟不包括任何类型的重置功能,这确实有一定的意义,但是将常量修改为以下仍然无助于测试通过...

I have been advised that my mock doesn't include any sort of reset function which does make a certain amount of sense, however amending the const to the following still does not help the test pass...

const emptyForm = <NgForm>{
    reset: () => null,
    resetForm: () => null,
    valid: false,
    value: {
      username: undefined,
      password: undefined,
    }
  };

错误日志:

zone.js:191 Uncaught TypeError: form.resetForm is not a function

推荐答案

看来 Karma 是从错误的测试中发送错误,或者至少误导了我错误的实际原因.

It appears that Karma was sending the error from the wrong test, or at least misdirecting me from the actual cause of the error.

在我放置 resetForm 之后:() =>null 到正确的模拟形式然后一切都很好.

After I placed resetForm: () => null into the correct mock-form then all is well.

这篇关于Angular2+ - 类型错误:form.reset 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 18:07:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1176874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!