-
-
Notifications
You must be signed in to change notification settings - Fork 873
More gradual testing intro #1818
More gradual testing intro #1818
Conversation
0c5c736
to
3f64a38
Compare
☔ The latest upstream changes (presumably e257e8b) made this pull request unmergeable. Please resolve the merge conflicts. |
Poo, it's a significant conflict :\ |
86d8c0b
to
3347d42
Compare
move tests after content Move back tests for route, complex component, and service sections fix spelling errors another spelling fix fix lifecycle link Fix links More seperation between test and features
3347d42
to
90c8f08
Compare
Also made several updates that address some of the initial comments in #1708 |
test('should list available rentals.', function (assert) { | ||
}); | ||
The launched Chrome web browser shows 10 successful tests. | ||
Ember generates tests that lint each file you create using [JSHint](http://jshint.com/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be changed to eslint now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of 2.11 (which I think the tutorial is at), its still installing jshint.
Running `ember test --server` will show a total of 7 failed tests out of 15. | ||
Each of the 6 tests defined above will fail, plus you'll notice one JSHint failure saying, `assert is defined but never used`. | ||
The tests we defined fail because a QUnit test fails if it is empty. | ||
Tests require a check for a specific condition (known as an `assert`). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great compromise on de-emphasizing testing.
Since we're using Mirage in our development environment, Mirage will return the data we've provided. | ||
When we deploy our app to a production server, we will need to provide a backend for Ember Data to communicate with. | ||
Since we've already set up Ember Mirage in our development environment, Mirage will return the data we requested. | ||
When we deploy our app to a production server, we will likely want to provide a backend server for Ember Data to communicate with to store and retrieve persisted data from. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...for storing and retrieving persisted data. Anything saved only in Ember Data's local store will be lost when we close our app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last sentence might be confusing because we are talking in this paragraph about using mirage vs a remote server. Will have to think about how to elaborate on providing a backend.
"...we will likely want to replace Mirage with a remote server for Ember Data to communicate with for storing and retrieving persisted data. A remote server will allow for data to be shared and updated across users."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This strikes me as a much more reasonable approach, especially for beginners.
The [`vendor` directory](../../addons-and-dependencies/managing-dependencies/#toc_other-assets) in Ember is a special directory where you can include content that gets compiled into your application. | ||
|
||
As Ember CLI runs, it takes the `ember-tutorial` CSS file and puts it in a file called `vendor.css`. | ||
The `vender.css` file is referenced in `app/index.html`, making the styles available at runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vendor.css
...
As Ember CLI runs, it takes the `ember-tutorial` CSS file and puts it in `vendor.css` (which is referenced in `app/index.html`). | ||
The addon works by generating a file called `ember-tutorial.css` and putting that file in the super-rentals `vendor` directory. | ||
|
||
The [`vendor` directory](../../addons-and-dependencies/managing-dependencies/#toc_other-assets) in Ember is a special directory where you can include content that gets compiled into your application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Ember CLI builds our app from our source code, it copies ember-tutorial.css
into a file called vendor.css
.
Run the tests again using the command `ember t -s`, and toggle "Hide passed tests" to show your new passing test. | ||
|
||
Now we are listing rentals, and and verifying it with an acceptance test. | ||
This leaves us with 2 remaining acceptance test failure (and 1 jshint failure): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... test failures...
@@ -256,7 +247,7 @@ export default Ember.Route.extend({ | |||
}); | |||
``` | |||
|
|||
Now visiting the root route `/` will result in the `/rentals` URL loading. | |||
Now visiting the root URL `/` will result in the `/rentals` URL loading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't route more correct here?
}); | ||
}); | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a quick breakdown of the test here.
assert.equal()
takes three arguments. The first two can be any expression, but are usually a test helper followed by the expected result. assert.equal()
simply returns true if the expressions are equal, and false if they aren't. The third is a user-friendly message that will be displayed in the test runner. A thorough test suite could be written with nothing but assert.equal()
calls.
The CLI `generate util` command will create a utility file and a unit test. | ||
We'll delete the unit test since we don't want to test Google code. | ||
Our app needs a single function, `createMap`, which makes use of `google.maps.Map` to create our map element, `google.maps.Geocoder` to lookup the coordinates of our location, and `google.maps.Marker` to pin our map based on the resolved location. | ||
Finally open the template file for our `rental-listing` component and add the new `location-map` component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may have noticed that this.get('location')
refers to a property location
we haven't defined. This property will be passed in to the component by its parent template.
|
||
We'll use a unit test to validate the service. | ||
Unit tests are more isolated than integration tests and acceptance test, | ||
and are intended for testing specific login within a class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
login logic
When the service calls `createMap` on our fake utility, we will run asserts to validate that it is called. | ||
In our first test notice that we expect four asserts to be run in line 17. Two of the asserts run in the test function, while the other two are run when `createMap` is called. | ||
|
||
In the second test, only one assert is expected (line 26), since the map element is fetch from cache and does not use the utility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetched
``` | ||
|
||
Now lets render our component using the `render` function. | ||
The `render` function allows use to pass a template string, so that we can declare the component in the same way we do in our templates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
test('should display rental details', function(assert) { | ||
this.set('rentalObj', rental); | ||
this.render(hbs`{{rental-listing rental=rentalObj}}`); | ||
assert.equal(this.$('.listing h3').text(), 'test-title'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add messages for continuity with earlier tests?
Thank you so much @theroncross for reviewing! I'll address these this weekend. |
fec6395
to
cace3d6
Compare
@toddjordan Nice work on this. Just sent in a PR to tweak, refine and simplify the language on the first three pages. I think we should merge what we have here and we can keep editorializing on it as we go. |
thanks @acorncom ! |
Additional tweaks and adjustments to the tutorial
Addresses #1718
Fixes #1863
Still in need of some proof reading, and would like a couple of people to walk through this version of the tutorial, since its a pretty big change.