Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step API #1075

Closed
leobalter opened this issue Dec 6, 2016 · 7 comments
Closed

step API #1075

leobalter opened this issue Dec 6, 2016 · 7 comments
Assignees
Labels
help welcome Type: Enhancement New idea or feature request.

Comments

@leobalter
Copy link
Member

leobalter commented Dec 6, 2016

@wycatz suggested this step API and I'm game for it.

It records steps inside a test. Given this example:

QUnit.test('references are granular', assert => {
  let { SubSub } = MakeSub();

  let obj = SubSub.create({ loud: true });
  let root = rootFor(obj);

  let state = new State(root);

  set(obj, 'name', 'Daniel');

  step('Update name');

  state.validateTags({ name: false });
  state.validateValues({ name: 'Daniel' });
  state.update();

  set(obj, 'loud', false);

  step('Update loud');

  state.validateTags({ loud: false });
  state.validateValues({ loud: false });
  state.update();
});

Each step can be recorded as a assert.ok(true), but printing the given description.

There's one con to consider for this API, which is the idea that assertions can be split in different tests specially inside nested modules.

Even though, it is an interesting approach to consider.

@leobalter leobalter added Type: Enhancement New idea or feature request. help welcome labels Dec 6, 2016
@leobalter
Copy link
Member Author

leobalter commented Dec 6, 2016

I did a quick prototype here: 3e515c3

@trentmwillis
Copy link
Member

I like this (and think there are several use cases within our own test suite for it), but seems like it is missing one thing: asserting that the correct steps happened.

Seems like maybe we need assert.step( tag ) and then assert.verifySteps([ tag1, tag2, ... ]).

@leobalter
Copy link
Member Author

That's a great and useful addition to the step api. I like it.

@trentmwillis trentmwillis self-assigned this Jan 20, 2017
trentmwillis added a commit to trentmwillis/qunit that referenced this issue Jan 20, 2017
Introduces the assert.step function which logs a passing assertion
for steps in a test. These steps are stored as string values to
help verify order of operations.

Fixes qunitjs#1075
trentmwillis added a commit to trentmwillis/qunit that referenced this issue Jan 20, 2017
Introduces the assert.verifySteps function to complement assert.step.
This acceptances an array of string values to compare to the steps
that have executed for the current test.

Fixes qunitjs#1075
trentmwillis added a commit to trentmwillis/qunit that referenced this issue Jan 24, 2017
Introduces the assert.step function which logs a passing assertion
for steps in a test. These steps are stored as string values to
help verify order of operations.

Fixes qunitjs#1075
trentmwillis added a commit to trentmwillis/qunit that referenced this issue Jan 24, 2017
Introduces the assert.verifySteps function to complement assert.step.
This acceptances an array of string values to compare to the steps
that have executed for the current test.

Fixes qunitjs#1075
@platinumazure
Copy link
Contributor

I'm not opposed to this landing, but I am not sure I understand the use case fully. I see the example above, but I'm not sure I fully understand what advantage this has over assert.ok(true) besides a slight readability improvement. Can anyone enlighten me, please?

@leobalter
Copy link
Member Author

Improves readability and it's also motivated by occurrence. ok(true) is being used here and there to flag given steps and their order. While this could be solved using the current API, step and verifyStep will provide an API with an clear goal to be used in these cases.

Afaik, this case was frequent in some async jquery tests and will certainly gonna be used by Ember as this is an original request from Yehuda Katz.

leobalter pushed a commit that referenced this issue Jan 24, 2017
Introduces the assert.verifySteps function to complement assert.step.
This acceptances an array of string values to compare to the steps
that have executed for the current test.

Fixes #1075
@platinumazure
Copy link
Contributor

@leobalter Thanks for the explanation, that works for me. That said, I'd love to see a longer-form case study for steps and step verification show up in the QUnit Cookbook maybe (unless that was covered in the documentation PRs?). If that seems worthwhile, I can create an issue.

@leobalter
Copy link
Member Author

it is! Using async code is one of the nice ways to use for examples. Async fns and promises will be great for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help welcome Type: Enhancement New idea or feature request.
Development

No branches or pull requests

3 participants