簡體   English   中英

組件內的Ember集成測試組件

[英]Ember Integration Test Component Within Component

我已經在應用ember-bootstrap中安裝了ember-bootstrap 然后,我創建了一個登錄表單組件。

app/templates/components/login-form.hbs ,有2個Bootstrap input和1個button ,分別是:

{{#bs-form onSubmit=(action "login") as |form| }}
    {{#form.group validation=emailValidation}}
        <label for="email">Email</label>
        <input id="email" value={{email}} name="email" class="form-control" oninput={{action (mut email) value="target.value"}} type="text" placeholder="Email" required>
    {{/form.group}}
    {{#form.group validation=passwordValidation}}
        <label for="password">Password</label>
        <input id="password" value={{password}} name="password" class="form-control" oninput={{action (mut password) value="target.value"}} type="password" placeholder="Password" required>
    {{/form.group}}
    {{bs-button defaultText="Login" type="primary" buttonType="submit"}}
{{/bs-form}}

當我在Components中進行集成測試時,似乎無法識別出this

test('it renders', function(assert) {
  assert.expect(3);
  assert.equal(this.$('input').attr('name'),'email','has Email');
  assert.equal(this.$('input').attr('name'),'password','has Password');
  assert.equal(this.$('button').text(),'Login','has Login');
});

input ,我得到undefined結果。 在Bootstrap中調用form.group組件的輸入以用於組件測試的正確方法是什么?

我相信您忘記了在測試中渲染組件; 那就是您需要添加以下內容:

this.render(hbs`{{login-form}}`);

在斷言之前。 您還需要更改第二個斷言以斷言組件中的第二個輸入。 無論如何; 我抄你的組件,然后在下面的修正測試玩弄 希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM