qunit-除了格式化外,文件的测试功能

发布于 2025-01-23 11:05:40 字数 800 浏览 6 评论 0原文

UI5在测试格式函数的UI5给出的示例IE

// Assert
assert.strictEqual(fnIsolatedFormatter("A"), "New", "The long text for status A is correct");
assert.strictEqual(fnIsolatedFormatter("B"), "In Progress", "The long text for status B is correct");
assert.strictEqual(fnIsolatedFormatter("C"), "Done", "The long text for status C is correct");
assert.strictEqual(fnIsolatedFormatter("Foo"), "Foo", "The long text for status Foo is correct");

效果很好,但是,适用于控制器文件的函数IE example.controller.js,产生错误>错误。

通过尝试测试_ontestFunction example.controller i确实得到以下错误

TypeError: Example._onTestFunction is not a function

问题:如何我测试不是格式>格式化的控制器文件的功能?

The example given by UI5 of testing the formatter functions i.e.

// Assert
assert.strictEqual(fnIsolatedFormatter("A"), "New", "The long text for status A is correct");
assert.strictEqual(fnIsolatedFormatter("B"), "In Progress", "The long text for status B is correct");
assert.strictEqual(fnIsolatedFormatter("C"), "Done", "The long text for status C is correct");
assert.strictEqual(fnIsolatedFormatter("Foo"), "Foo", "The long text for status Foo is correct");

Works out very well, however, the same testing applied to functions of a controller file i.e. Example.controller.js, produces an error.

By trying to test the _onTestFunction of the Example.controller i do get the following error:

TypeError: Example._onTestFunction is not a function

Question: How do i test functions of a controller file that isn't formatter ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

披肩女神 2025-01-30 11:05:40

要测试控制器,您需要实例化一个:
令ControllerDerneTest = New Controller(...)。如果控制器具有任何依赖关系(通常是这种情况),则需要嘲笑这些依赖项。为此,请使用诸如sinon之类的框架。然后,您可以在每个测试中指定这些模拟应如何行为。实例化控制器后,您可以执行方法并添加断言。
在您的情况下,您似乎正在尝试调用_onteStfunction不是在对象上,而是在控制器的“定义”上调用。这不像预期的那样包含该方法,并导致错误。

To test a controller, you need to instantiate one:
let controllerUnderTest = new Controller(...). If the Controller has any dependencies (as this is usually the case), these dependencies need to be mocked. For this, use a framework such as sinon. Then you can specify in each test how these mocks should behave. Once you have instantiated the controller, you can execute a method and add assertions.
In your case, it looks like you are trying to call the _onTestFunction not on an object, but on the "definition" of the Controller. This does not contain the method, as expected, and results in the error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文