gpt4 book ai didi

javascript - 在 Ember 集成测试期间调试呈现的 HTML 和代码

转载 作者:行者123 更新时间:2023-11-29 19:08:30 24 4
gpt4 key购买 nike

我想在一个页面中呈现我的组件的测试,这样我就可以看到我在某些方法中插入的调试。

出于某种原因,我的测试似乎没有正确加载数据,我想看看它正在加载什么。

不幸的是,QUnit 只显示我在 asserts 中输入的内容我想知道是否有办法在一个页面中单独查看我的测试,以便我可以查看控制台日志

这是测试的框架:

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { clickTrigger } from 'frontend/tests/helpers/ember-power-select';

moduleForComponent('dynamic-input-field', 'Integration | Component | dynamic input field', {
integration: true
});

test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
this.set(...);

// render the component
this.render(hbs`{{my-component myProperty}}`);

// actions of user here
clickTrigger(); //this opens the ember-power-select
assert.equal($('.ember-power-select-dropdown').length, 1, 'Dropdown is rendered');
// check if it is rendering the elements and if it is excluding one element
assert.equal('Field Four',$($('.ember-power-select-option')[2]).text().trim());
});

编辑:我只使用 assert.equal() 就弄清楚了问题所在.少了一个$() (jQuery 函数)。示例:

assert.equal('Field Four',$($('.ember-power-select-option')[2]).text().trim());

如果不使用 assert.equal() 来查看渲染的组件仍然很棒

最佳答案

尝试使用 debugger; statement在组件的 didRender lifecycle hook 中,像这样:

export default Ember.Component.extend({
didRender() {
/* jshint ignore:start */
debugger;
/* jshint ignore:end */
},

// the rest of your code...
});

它会在您的集成测试中暂停代码执行,您可以在控制台中使用您的代码。如果您在浏览器中使用 QUnit Runner,HTML 渲染将在运行器的显示区域暂停,您也可以检查它。

我创建了一个 Ember Twiddle example来演示这个解决方案。

关于javascript - 在 Ember 集成测试期间调试呈现的 HTML 和代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40937366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com