ember-learn / guides-source

This repository contains the Ember.js Guides
https://guides.emberjs.com/
MIT License
158 stars 496 forks source link

Update Section: Testing #458

Open MelSumner opened 5 years ago

MelSumner commented 5 years ago

This section is already pretty up to date, looks like someone went over it recently with the RFC-232 changes.

Some things to add:

kovalchik commented 5 years ago

I was reading through the Octane testing section the other day and noticed that there's still a lot of usages of this.set. For example, in the components testing section:

// set the outer context to red
this.set('colorValue', 'red');
await render(hbs`<PrettyColor @name={{this.colorValue}} />`);
assert.equal(this.element.querySelector('div').getAttribute('style'), 'color: red', 'starts as red');

I know there's some instances where using set is required, but when setting up my tests, I was able to directly assign outer context values without any issues. Should updating the examples in the testing section to not use get and set also be a checklist item?

// set the outer context to red
this.colorValue = red;
await render(hbs`<PrettyColor @name={{this.colorValue}} />`);
assert.equal(this.element.querySelector('div').getAttribute('style'), 'color: red', 'starts as red');
ijlee2 commented 5 years ago

@MelSumner @jenweber If it's ok with you and the Ember Learning Team, I'd like to help improve the Octane documentation for testing. I am planning to take a break from work on July 26-31 and work on personal projects.

I looked at how the Testing section currently reads from the perspective of a beginner. Some of the contents are great, but I thought the Testing section, overall, can use more polish.

I would like to reorganize existing content, create more diverse test examples (many examples only show testing what happens after get or set), and provide additional information. By doing so, I think I can address several of the items that @MelSumner listed above.

What are your thoughts?

Best,


Proposed structure for Testing:

toddjordan commented 5 years ago

Thanks for being willing to take on making tests more accessible to new users <3

I have a few comments...

  1. I think probably 3rd party tools should be a separate section at the end. Installing many of these tools change the way you write tests and since the rest of the guides are written assuming out of the box tooling I think it could cause a new learner some grief. Also, what is the criteria for including test tools?
  2. The first thing in "How to write tests" should not be "writing custom assertions". In fact I've found that to be a very rare task. Also maybe that section should be more like "Advanced Topics", and also moved to the end.
  3. Stubs is potentially a big topic with divergent views and should be written carefully if we want to broach in its own section.
  4. in "How to run" we should go over all flags (--server, --reporter, etc)
  5. The container is a common concept across all tests, not just unit. this.owner is now implicit in all tests I think. Also this.element should be doc'd. Probably "Testing Basics" is still needed
toddjordan commented 5 years ago

The other thing we'll need to be careful for is not providing a bunch of advanced examples interleaved with beginner focused examples. We want to make a clear path for a beginner to get bootstrapped and writing tests, and not get them bogged down in trying to understand scenarios that they may not need, or may not even be prudent for them to do at first.

ijlee2 commented 5 years ago

@toddjordan, much thanks for your feedback. I agree with many of your points and can clarify my ideas further (number scheme matching yours):

1. 3rd party tools

2. How to write tests section

3. Stubs

4. Flags in How to run

5. Container

6. Advanced examples

Thanks again!

Gaurav0 commented 5 years ago

@ijlee2 @toddjordan @MelSumner @jenweber Can we update this issue to clarify what remaining tasks still need to be done? Thanks!

ijlee2 commented 5 years ago

Hi, @Gaurav0. Thanks for asking.

I don't have edit permission to update Melanie's comment, so let me copy-paste it here:

Regarding the first 2 points: In the updated Introduction section and the new Test Types section, I think we explained enough that application = acceptance and rendering = integration, that the reader will implicitly know why a certain test belongs to a certain folder.

I'm not sure about what Melanie had had in mind with regards to the points 6, 7, 8, and 9.


With regards to the list of to-dos that I had had in mind, I completed the Introduction and Different Types of Tests, but have been slacking off on writing How to Write Tests. I hope to have something written about good practices as a result of my upcoming EmberFest talk. I can definitely use your help with talking about test helpers, submodules, and stubs.

The remaining sections—from Testing Adapter to Testing Utility in my list—I think we could review what has been written already and see how we need to create/update/delete content. I personally would like to see sections on testing adapters and serializers because the Guides currently don't talk about them and provide examples. As a new developer, I have ideas of what I would test but don't know how I would write tests for them.


What are your thoughts?

Best,

Gaurav0 commented 5 years ago

Sounds good. I put some stubs stuff in unit testing basics for now, when you get to "How to write tests" we can see if we can move it there.

Gaurav0 commented 5 years ago

Melanie copied the issue from my analysis. 6 has to do with using async/await on functions that return promises. 7 is about query parameters, currently shoehorned into controllers. 8 is about importing a native class rather than using this.owner. 9 is all about the run loop, what it is and why it needs attention during tests.

ijlee2 commented 5 years ago

@Gaurav0 Thanks for your explanation. Yeah, I need help from more people with writing the testing doc, so it'd be great to have your help.

I'm not sure what time zone you're in (I'm in central), but maybe we can do a video meeting to talk about how to divide the remaining tasks? I can be available at most times starting tomorrow (Sep 18, Wed). Would that be all right with you?

Gaurav0 commented 5 years ago

I'm in Eastern. Let's discuss meeting on Discord.