Giter VIP home page Giter VIP logo

Comments (9)

kturney avatar kturney commented on June 19, 2024 5

@rwjblue provided a solution here https://youtu.be/PwQAj5UU9ng?t=1h25m30s.

Taking that info, I've made the following helper for my tests:

import { waitUntil } from 'ember-native-dom-helpers';
import Ember from 'ember';

export default function waitForError(opts) {
  const orig = Ember.onerror;

  let error = null;
  Ember.onerror = (err) => {
    error = err;
  };

  return waitUntil(() => error, opts).finally(() => {
    Ember.onerror = orig;
  });
}

I then replace

assert.expectAssertion(() => {
  render(hbs`
    {{button-hero
      align='center'
      icon='svg-add'
      theme='secondary'
      text='Create New Group'
    }}
  `);
}, 'Assertion Failed: An action is required');

with

const [ err ] = await Promise.all([
  waitForError(),
  render(hbs`
    {{button-hero
      align='center'
      icon='svg-add'
      theme='secondary'
      text='Create New Group'
    }}
  `)
]);

assert.equal(err.message, 'Assertion Failed: An action is required', 'correct assertion');

maybe there's a way to wrap up that same logic into something that looks more like assert.expectAssertion

from ember-qunit-assert-helpers.

RobbieTheWagner avatar RobbieTheWagner commented on June 19, 2024 2

Would love to see support for this baked in. Anything we can do to get this over the finish line?

from ember-qunit-assert-helpers.

rwjblue avatar rwjblue commented on June 19, 2024 1

Updating issue description...

from ember-qunit-assert-helpers.

rwjblue avatar rwjblue commented on June 19, 2024

Was chatting with @workmanw in slack about this, and came up with master...async-wip as a possible solution for expectAssertion.

from ember-qunit-assert-helpers.

rwjblue avatar rwjblue commented on June 19, 2024

I think next steps are to put some actual tests together and get the other assertion helper methods in line with that WIP (and fix my typos in the WIP).

Any takers?

from ember-qunit-assert-helpers.

alexdiliberto avatar alexdiliberto commented on June 19, 2024

I was taking a bit of a stab at it, issue I'm running into is that render now returns a promise which has it's body execute on the next iteration of the runloop. (https://github.com/emberjs/ember-test-helpers/blob/v0.7.0-beta.8/addon-test-support/setup-rendering-context.js#L98) So the expectAssertion code will always return before the component's init() hook has even fired.

I'll push up what I have even though it's not complete...#21

from ember-qunit-assert-helpers.

heathharrelson avatar heathharrelson commented on June 19, 2024

Our apps make fairly extensive use of assertions to document assumptions. I tried upgrading one of my apps to the new testing API while I was at EmberConf, and this broke around 100 of the tests. Do you have any idea how to get this working with the new API? Is there anything I could do to help?

from ember-qunit-assert-helpers.

heathharrelson avatar heathharrelson commented on June 19, 2024

EDIT: Note that my solution below didn't work anymore after updating to use @ember/test-helpers.

For what it's worth, I ended up working around this in my projects by just wrapping the render call in a try and asserting the content of the message in the catch block:

test('it throws an exception if no range validation is present', async function(assert) {
  try {
    await render(hbs`{{clipped-numeric options=options}}`);
  } catch (e) {
    assert.equal(e.message, 'Assertion Failed: A single optional_in_range validation is required');
  }
});

from ember-qunit-assert-helpers.

shokmaster avatar shokmaster commented on June 19, 2024

Any news about this issue?

from ember-qunit-assert-helpers.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.