lundi 17 décembre 2018

Ember.js test page keeps refreshing automatically

I'm trying to follow an example integration test from here: https://guides.emberjs.com/release/testing/testing-components/ (Testing Actions)

My problem is that the Test output keeps refreshing automatically, perpetually, for some reason?

Test code:

test('Can handle submit action', async function (assert) {
    /*
    * THIS TEST HAS PROBLEMS
    * THE PAGE CONSTANTLY REFRESHES FOR THIS TEST, NO IDEA WHY, NEED TO INVESTIGATE
    */
    assert.expect(1);

    // test double for the external action
    this.set('externalAction', (actual) => {
      const expected = {inputValue: 'test'};
      assert.deepEqual(actual, expected, 'submitted value is passed to external action');
    });

    await render(hbs``);

    // click the button to submit the form
    await click('#submitButton');
  });

Component.js:

import Component from '@ember/component';
import {computed} from '@ember/object';

export default Component.extend({
  inputValue: '',
  submitText: 'Save',
  inputIsValid: computed('inputValue', function () {
    return this.inputValue.length > 3;
  }),

  actions: {
    save(inputValue) {
      if (this.inputIsValid) {
        this.saveAction(inputValue); // pass action handling to route that uses component
      }
    }
  }
});

component template:

<br>
<br>
<form onsubmit=>
    
      <div style="color: red" class='validationMessage'>
        Hey it is not valid!
      </div>
    

    <label id="inputLabel"></label>
    
    <br>
    <button type="submit" id="submitButton" class="btn btn-primary"></button>
</form>


I thought it might be because the form in the template keeps submitting, but that can't be the case since it should only click submit once. Any help much appreciated!




Aucun commentaire:

Enregistrer un commentaire