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

Update README and tests with comments from Juicy/imported-template/pull/31 #32

Merged
merged 4 commits into from
Oct 3, 2017

Conversation

tomalec
Copy link
Member

@tomalec tomalec commented Oct 2, 2017

Juicy/imported-template/pull/31

  • reset mock server,
  • don't use mock server if mockable by static files,
  • add pre-test control expectation to ensure conditions,
  • few typographical changes.

…ll/31

 - reset mock server,
 - don't use mock server if mockable by static files,
 - add pre-test control expectation to ensure conditions,
 - few typographical changes.
Copy link
Contributor

@warpech warpech left a comment

Choose a reason for hiding this comment

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

Just 3 minor things. The important thing is that the tests fail in Travis.

@@ -37,6 +37,10 @@
});

it('should remove stamped nodes after content is cleared', function(){
var parent = myEl.parentNode;
// pre-test conditions
expect(parent.children.length).to.be.equal(2);
Copy link
Contributor

@warpech warpech Oct 3, 2017

Choose a reason for hiding this comment

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

Can expect for preconditions be in beforeEach?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it's a good practice? I've never seen such a use - assertion in setup? Aren't we going to write tests for tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've never seen testing for pre-test conditions in a test either. The fact that the test has to check preconditions looks like a design flaw in the testing framework. Maybe we can do some resetting of the parent container in beforeEach that makes this check redundant?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do have such resetting at

myEl = fixture('juicy-html-fixture').querySelector('template[is="juicy-html"]');

@alshakero as this was your idea to test preconditions could you elaborate?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a testing expert. But when I see a test that is prone to fool me into a passing test, I try to test before and after the action in question.

For example, if we want to test delete:

expect(myObj.myVar).toBe(undefined)

... is very likely to pass even if delete is broken. That's why I usually do:

expect(myObj.myVar).not.toBe(undefined);
delete myObj.myVar;
expect(myObj.myVar).toBe(undefined)

And the tests I thought needed a control check are the ones that test for null and children.length == 1. Checking if children.count == 2 then remove(child) then children.count == 1 sounds like a more robust test than only children.count == 1.

However, I'm not asserting and merely suggesting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well beforeEach makes sure we have elements there

myEl = fixture('juicy-html-fixture').querySelector('template[is="juicy-html"]');

Doing expect is just double checking. The question is whether it is a confusing paranoid mode, or better safe than sorry approach, as beforeEach uses <test-fixture> which may also have bugs.

Copy link
Member Author

Choose a reason for hiding this comment

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

WDYT @warpech ?

Copy link
Contributor

Choose a reason for hiding this comment

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

You have convinced me, let's keep it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't 100% convinced either. I'm fine to keep it, but I'd like to avoid going to paranoid, to make tests easier to read and write.

@@ -17,7 +17,7 @@
<test-fixture id="juicy-html-with-content">
<template>
<!-- nest to workaround test-fixture bug -->
<div><template is="juicy-html" content="/mock/smth">
<div><template is="juicy-html" content="../mock/smth.html">
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you use relative path ../, but in test/content-legacy/no-content.html you use an absolute path /. This should be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

solved

//whenever the this returns true the request will not faked
return !url.match(/mock\//);
//whenever this returns true the request will not faked
return !url.match(/mock\/204/);
});
server.respondWith('GET', '/mock/204', [204, {"Content-Type": "text/html"}, '']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change the responses generated by sinon to be /generate/204 instead of /mock/204? This will make it easier to distinguish.

Or rename the mock directory to static.

@tomalec
Copy link
Member Author

tomalec commented Oct 3, 2017

BTW, once we will agree on all the changes, I'll squash commits, not to pollute commit log with Travis related problems.

@alshakero
Copy link
Contributor

Might be hidden by GH #32 (comment)

@tomalec tomalec merged commit 60659d9 into master Oct 3, 2017
@warpech warpech deleted the polish-tests-and-README branch October 18, 2017 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants