-
Notifications
You must be signed in to change notification settings - Fork 90
Fixes #953 - homepage unit test #992
Fixes #953 - homepage unit test #992
Conversation
process.nextTick(function() { | ||
blogSection.getDOMNode().querySelector(".featured-post .entry-title").textContent.should.eql("What’s next for Thimble?"); | ||
done(); | ||
}); |
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.
@toolness in this comment you mentioned about using sinon to trigger the feed callback. Could you give me more pointers?
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.
Hmm, so for now I think what you've got is actually ok, so long as you add a comment above line 18 that explains how the process.nextTick
is used so the stub blog post loader loads the posts by then.
However, if you do want to go the extra mile/kilometer, that's totally awesome! It'd likely involve the following steps:
-
Writing a fake
loadBlogPosts
function that you pass as a prop toHomePage.BlogSection
. You could use a sinon spy for this, or you could actually just hand-write a fake function that looks something like this:var respondWithBlogPosts; var fakeLoadBlogPosts = function(cb) { /* Hold on to the callback so we can trigger it later from our tests. */ respondWithBlogPosts = cb; };
-
You might want to change
stub-blog-feed-loader.js
so it also exportsFAKE_POSTS
. You'll likely want your fake callback to pass this back to the component.
That's the basics... Writing tests is mostly just about "hacking" the inputs/dependencies of your code to make sure they provide the expected output, and preferably doing so in a way that's easy to understand and maintain. Feel free to experiment with other ideas if you don't like the ones I provided.
Could you add at least one test that verifies how the component should behave when it's waiting for blog posts to load? You can even fix #955 real quick while you're at it if you want 😁 |
blogSection = stubContext.render(HomePage.BlogSection); | ||
}); | ||
|
||
describe("blogSection", function() { |
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.
@toolness I have this describe
inside of the describe("HomePage"
, does it help solving the issue you mentioned? Or I could remove this inner one and rename the outer describe
from HomePage
to HomePage.BlogSection
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.
Yeah, I recommend just removing the inner one and renaming the outer one--that way we can keep each test suite completely isolated from one another.
The only reason we might want to nest describe
calls is if two components or "types" of test suites need to share common infrastructure--in which case the beforeEach
/afterEach
of the top-level describe
could do the setup/teardown common to both sub-suites. But until we definitely have a need for that, I think we should just keep the different suites isolated from one another as much as possible. (Unfortunately, I don't think all the test suites I've written follow this principle--sorry I'm not practicing what I'm preaching... 😞 )
oh yea don't forget the |
</p> | ||
<a className="more" href={this.props.data.link}>Continue reading</a> | ||
</div> | ||
: null |
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 non-JS users and search engines, I wonder if it might be useful to at least link to the blog instead of not showing anything at all? Guess we can just file an issue for it--and anyways, once we move to the dynamic lightweight server in #585, we will be able to fetch the blog info on the server side and deliver this component completely pre-rendered, so not really a big deal I guess.
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.
Before the data has been loaded from Google API we don't have the any info about the latest blog posts, do we? 😮 On the initial render we are just passing https://github.com/mozilla/teach.webmaker.org/blob/develop/pages/home.jsx#L94-L105 as props
to <FeaturedPost>
.
Both of the <FeaturedPost>
and <LatestPosts>
won't show but there will be a "See all blog posts" link that links to http://blog.webmaker.org/. I hope that's sufficient 👀
Ack, I'm realizing that there are a few comments I should've made on your original PR for the blog post components:
Anyhow, neither of these are blockers or anything, but if you want to fix them in this PR that'd be rad, or we can file a separate issue for them. |
raaaad, now I know another thing to save my keystrokes! review again @toolness? 😬 |
Woot, this looks GREAT! Thanks mavis! |
Fixes #953 - homepage unit test
This fixes #953