简体   繁体   English

在应用程序路径中渲染模态的Qunit

[英]Qunit for rendering modal in application route

In my application route, I have code provided from the ember website on how to render the opening and closing of modals. 在我的应用程序路线中,我从ember网站提供了有关如何渲染模式的打开和关闭的代码。 https://guides.emberjs.com/v1.10.0/cookbook/user_interface_and_interaction/using_modal_dialogs/ https://guides.emberjs.com/v1.10.0/cookbook/user_interface_and_interaction/using_modal_dialogs/

export default Ember.Route.extend({
  actions: {
      openModal: function(name, controllerName) {
        this.render(name, {
          into: 'application',
          outlet: 'modal',
          controller: controllerName
        });
      },
      closeModal: function() {
        this.disconnectOutlet({
          outlet: 'modal',
          parentView: 'application'
        });
      }
    }
});

I've been trying to find examples of how to do a unit test for the rendering action but could not find much documentation. 我一直在尝试找到有关如何对渲染操作进行单元测试的示例,但找不到太多的文档。

In my unit test for the application route, just for the sake of triggering the action on the route and seeing what would happen this is what I have and the error I get. 在我对应用程序路由的单元测试中,仅是为了触发该路由上的操作并查看将发生什么,这就是我所拥有的以及所得到的错误。 Thank you for any guidance anyone might be able to provide. 感谢您提供任何人都可以提供的指导。

test('route open modal', function(assert) {
  let route = this.subject();
  route.send('openModal', 'cancel-modal');
  assert.ok(route);
});


Died on test #1     at Module.callback (http://localhost:4200/exampleApp/assets/tests.js:1113:24)
    at Module.exports (http://localhost:4200/exampleApp/assets/vendor.js:140:32)
    at requireModule (http://localhost:4200/exampleApp/assets/vendor.js:32:18)
    at TestLoader.require (http://localhost:4200/exampleApp/assets/test-support.js:7124:7)
    at TestLoader.loadModules (http://localhost:4200/exampleApp/assets/test-support.js:7116:14)
    at Function.TestLoader.load (http://localhost:4200/exampleApp/assets/test-support.js:7146:22)
    at http://localhost:4200/exampleApp/assets/test-support.js:7030:18: Cannot read property 'state' of undefined@ 31 ms
Source:     
TypeError: Cannot read property 'state' of undefined
    at parentRoute (http://localhost:4200/exampleApp/assets/vendor.js:41309:64)
    at buildRenderOptions (http://localhost:4200/exampleApp/assets/vendor.js:41371:27)
    at Class.render (http://localhost:4200/exampleApp/assets/vendor.js:41191:27)
    at Class.openModal (http://localhost:4200/exampleApp/assets/exampleApp.js:1118:14)
    at Class.send (http://localhost:4200/exampleApp/assets/vendor.js:40471:39)
    at Class.superWrapper [as send] (http://localhost:4200/exampleApp/assets/vendor.js:54491:22)
    at Object.<anonymous> (http://localhost:4200/exampleApp/assets/tests.js:1115:11)
    at runTest (http://localhost:4200/exampleApp/assets/test-support.js:3471:30)
    at Test.run (http://localhost:4200/exampleApp/assets/test-support.js:3457:6

Two things. 两件事情。

  1. You're using an outdated solution. 您使用的是过时的解决方案。 The documentation page you've linked to is two years old. 您链接到的文档页面已有两年历史了。

    Instead, use a modern addon for modal dialogs. 取而代之的是,将现代插件用于模式对话框。 I personally prefer liquid-tether , but there are many other solutions available . 我个人更喜欢液态系绳 ,但还有许多其他解决方案可用

  2. You're using a unit test while trying to render something. 您在尝试渲染某些东西时正在使用单元测试。 Unit tests are for running methods and checking their return values. 单元测试用于运行方法并检查其返回值。 To test a modal dialog being rendered, you need an acceptance test. 要测试正在渲染的模式对话框,您需要进行验收测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM