Angular2+ - 类型错误:form.reset 不是函数 [英] Angular2+ - TypeError: form.reset is not a function

查看:35
本文介绍了Angular2+ - 类型错误:form.reset 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从继承的问题查找 [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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆