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

Assert settled() only takes an object as first argument #303

Closed
wants to merge 7 commits into from

Conversation

snewcomer
Copy link
Contributor

Fixes #283

@rwjblue
Copy link
Member

rwjblue commented Jan 18, 2018

Also addresses #300.

After thinking about this more, let’s just make this work without error for now. In the long run, I want to deprecate the options argument completely and making this an assertion now then removing it later feels odd to me...

@snewcomer
Copy link
Contributor Author

That makes sense. So does that mean close the PR? Or just debug/deprecate?

@@ -200,5 +201,8 @@ export function isSettled() {
export default function settled() {
let options = arguments[0];

assert(`The 'settled' (formerly 'wait') testing helper only accepts 'undefined' or an object. You passed ${options}`,
typeof options === 'undefined' || typeof options === 'object' && options !== null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is undefined a valid value? settled() and settled(undefined) are somewhat similar but I don't think we should encourage passing undefined here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that’s what the value appears to be for settled(). I don’t think actually passing undefined is useful in anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that is why I don't think we should mention it that way in the assertion message. also we could check if arguments.length > 0, because IMHO settled(undefined) should also throw the assertion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Sure, that makes sense.

@rwjblue
Copy link
Member

rwjblue commented Jan 20, 2018

@snewcomer - Ya, if you are interested in updating that would be great. Basically we should avoid the in checks completely if the first arg is not typeof obj === ‘object’ && obj !== null...

@rwjblue
Copy link
Member

rwjblue commented Jan 20, 2018

Another option here that is growing on me, is to treat the change in wait behavior as a regression but keep settled with the assertion that you originally submitted in this PR (with the tweaks that @Turbo87 mentioned). In order to do this, wait changes from a simple reexport to something that sanitizes the input....

Thoughts?

@snewcomer
Copy link
Contributor Author

Ah great points! The line below had to be refactored b/c as a callback w/ apply, undefined would be the argument.

https://github.com/emberjs/ember-test-helpers/blob/master/addon-test-support/%40ember/test-helpers/setup-application-context.js#L24

And I like the idea of changing the wait helper to sanitize the input. Would it just simply ignore the passed in 3000 for example?

@snewcomer
Copy link
Contributor Author

Pinging this again. The test is actually passing I believe.

screen shot 2018-01-31 at 7 16 31 am

@kybishop
Copy link

kybishop commented Feb 1, 2018

@snewcomer correct! The linter is failing, but the tests themselves are good: https://travis-ci.org/emberjs/ember-test-helpers/jobs/333478168#L500

You should be able to test fixes with yarn lint

@snewcomer
Copy link
Contributor Author

@rwjblue pinging ya on this one if you still think is relevant :)

.then(settled);
.then(() => {
return settled();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can still use short form: .then(() => settled());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87 Ah I just realized something. The fulfillment value for the Promise callback is undefined. So to not trip up anybody passing settled to a Promise callback, we do have to somehow guard for undefined.

Are you ok with this? 2007b44

@Turbo87 Turbo87 added the bug label Feb 10, 2018
let options = arguments[0];

if (arguments.length > 0) {
export default function settled(options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was documentation will see that there is a parameter and document it as such, but as mentioned in #314 this parameter is kinda private so we should keep let options = arguments[0]; instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87 Another good point. How about now 😆

22d1538

@Turbo87 Turbo87 changed the title assertion for settled if pass in # close #283 Assert settled() only takes an object as first argument Feb 10, 2018
@rwjblue
Copy link
Member

rwjblue commented Feb 10, 2018

I took a stab at an alternative strategy in #317, what do y'all think?

@rwjblue rwjblue closed this in #317 Feb 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants