Skip to content

Reading/Editing/Octaning “Testing” section - #594

Merged
rwjblue merged 36 commits into
ember-learn:octanefrom
muziejus:octane-testing
Mar 15, 2019
Merged

rwjblue merged 36 commits into
ember-learn:octanefrom
muziejus:octane-testing

Conversation

@muziejus

Copy link
Copy Markdown
Contributor

Working on #588

@muziejus

Copy link
Copy Markdown
Contributor Author

I don't know how to properly separate two PRs at once, so the first five commits here come from my other current PR. Nevertheless, I'm using this space to take some notes on the testing pages:

  1. In the "Introduction," I think that this.owner is described too abruptly.

In the example below, we import the setupTest function from ember-qunit and call it with the hooks object to setup the test context with access to the this.owner property. This provides us direct container access to interact with Ember's Dependency Injection system.

The link to the Dependency Injection guide is handy, but it's not quite clear why, if this.owner is a property of the test, that it "owns" an ApplicationInstance. It may be better to use text like:

In the example below, we import the setupTest function from ember-qunit and call it with the hooks object to setup the test context. This uses Ember's Dependency Injection system to create an ApplicationInstance that serves as the "owner" for objects that are instantiated during testing. We can access the ApplicationInstance with the this.owner property to "look up" (i.e. instantiate and / or retrieve) objects.

@muziejus

Copy link
Copy Markdown
Contributor Author

Next, the testing sections present a few difficulties for octanization:

  1. In "Testing Basics," there is a whole section to testing observers. As @pzuraq notes, "observers and event listeners are not a recommended pattern anymore," so maybe this section should be cut entirely or refactored to use @tracked.

  2. The first test in "Testing Components" relies on attributeBindings. These are, if I understand correctly, not to be used in Octane, as something like a component's style attribute can be set programmatically with something like <div style={{this.style}}>…</div>. I would propose a simpler test that uses Glimmer component basics.

  3. I don't know what the Octane orthodoxy is vis-à-vis controllers, but given that the Controllers section of the guides is not on the sidebar, that it has not been updated to use native class syntax, and that the controllers section of the "Routing" guide is gone, I think perhaps it's time to retire the controllers testing section, as well?

@muziejus muziejus changed the title [WIP] Reading/Editing/Octaning “Testing” section Reading/Editing/Octaning “Testing” section Mar 13, 2019

@rwjblue rwjblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like some of the changes here are inherited from #588, I'll comment inline on the testing stuff in this PR but we'll probably need to land #588 first and then rebase this (I'm happy to take care of that for you if you'd like, when the time comes).

@rwjblue

rwjblue commented Mar 14, 2019

Copy link
Copy Markdown
Contributor

In "Testing Basics," there is a whole section to testing observers. As @pzuraq notes, "observers and event listeners are not a recommended pattern anymore," so maybe this section should be cut entirely or refactored to use @Tracked.

Ya, agreed. Lets remove the observer test example section.

@rwjblue

rwjblue commented Mar 14, 2019

Copy link
Copy Markdown
Contributor

The first test in "Testing Components" relies on attributeBindings. These are, if I understand correctly, not to be used in Octane, as something like a component's style attribute can be set programmatically with something like

…
. I would propose a simpler test that uses Glimmer component basics.

I actually think the example there is still valid. In a @glimmer/component world style attribute does not have any special merging behaviors. If you wanted to have a component that took color as an argument, it would still mostly need the same code.

I'd write the example component as:

import Component from '@glimmer/component';

export default class PrettyColor extends Component {
  get style() {
    return `color: ${this.args.name}`;
  }
});
<div style={{this.style}}>
  Pretty Color: {{@name}}
</div>

@rwjblue

rwjblue commented Mar 14, 2019

Copy link
Copy Markdown
Contributor

but given that the Controllers section of the guides is not on the sidebar, that it has not been updated to use native class syntax

I think it still needs to be updated, octane does not remove the need for controllers at all. However, since the controllers section in the sidebar is removed, perhaps we should just remove the controller testing section from the sidebar for now as well. That way we can bring both back together, when they are ready.

@rwjblue rwjblue added the Octane label Mar 14, 2019
Comment thread guides/release/services/services.md Resolved
@muziejus

Copy link
Copy Markdown
Contributor Author

@rwjblue and @efx, any thoughts on adding a bit more explanation to this.owner in the introduction section? The controllers test also describes it better than the intro, imo:

Next we use the owner API to gain access to the controller we'd like to test.
Using the this.owner.lookup method we get the instance of the PostsController and can check the action in our test.
The this.owner.lookup helper returns objects generated by the framework in your applications
and is also exposed in tests for your usage. Here it will return a singleton instance of the PostsController.

@rwjblue

rwjblue commented Mar 15, 2019

Copy link
Copy Markdown
Contributor

OK, I think we need a rebase now (to drop out the commits that were also in #588). Does that make sense? Also, happy to help with that if you'd like...

muziejus and others added 16 commits March 14, 2019 22:33
The asynchronous helpers were formatted
`<li>helper-name<ul><li>description…`, but the markdown was not
rendering correctly. The synchronous helpers were formatted
`<li>helper-name: description…`. This unifies the style.
@ghost

ghost commented Mar 15, 2019

Copy link
Copy Markdown

@muziejus I think discussing how we introduce the owner API is a good idea. I had a similar problem with how the current guides talked about services: #300 (comment)
I prefer linking to the better definition and even the API documentation itself. Having 2 definitions of an API floating around in the guides could lead to confusion as you rightly note.

@muziejus

Copy link
Copy Markdown
Contributor Author

@efx Good point about not duplicating definitions, as I sort of do that in my proposal, copy and pasting from the dependency injection page's discussion of ApplicationInstance.

Could the glossary help here?

Similarly, something like:

In the example below, we import the `setupTest` function from `ember-qunit` and call it with the `hooks` object to setup the test context. This provides us with the `this.owner` property. As the [API docs note]:

> When Ember's [Dependency Injection] system creates an [ApplicationInstance], it exposes a `this.owner` property that serves as the "owner" for objects that are instantiated during testing. We can access the `ApplicationInstance` with the `this.owner.lookup` to "look up" (i.e. instantiate and / or retrieve) objects. Similarly, we can register...

Might be good, since it marks that we're relying on a different document for the quoted material. That may be friendlier than just a link.

@rwjblue rwjblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few things;

  • The service stubbing example should assume the service has marked currentLocation as @tracked, and therefore doesn't need @computed
  • The "Testing Computed Properties" section should be refactored to be about testing tracked properties, OR we should scale down the "Testing Computed Properties" section and add a larger "Testing Tracked Properties". For now I think the first option is "easier" and I made inline suggestions to that effect...

This is looking really nice, thank you for working on it!

@ghost

ghost commented Mar 15, 2019

Copy link
Copy Markdown

@muziejus big 👍 from me to your revision. Honestly don't think we even need to quote the API documentation as it is linked. I also want to say we should continue any wording tweaks outside of this PR because the grand work you're doing here should be be merged once the technical review notes are done.

rwjblue and others added 20 commits March 15, 2019 10:39
@muziejus

Copy link
Copy Markdown
Contributor Author

@rwjblue Per your rec, I deleted (4e8badb) the section on testing observers, but I do think it'd be useful to instead replace it with a section on testing tracked properties, so that may be a way to advance the points you bring up.

@muziejus

Copy link
Copy Markdown
Contributor Author

@efx Thanks. You're right… I think once the code is somewhat stable I can have a stab at the language in separate PRs to work on better comprehension. As a relative noob, I think I have a couple insights into sniffing out where things get too confusing too quickly!

@rwjblue
rwjblue merged commit add3166 into ember-learn:octane Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants