Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

refactor(compileSpec): make tests consistent #15141

Merged
merged 1 commit into from
Oct 14, 2016

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Sep 15, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
refactor

What is the current behavior? (You can also link to an open issue here)
Tests are duplicated and have non-optimal expects

What is the new behavior (if this is a feature change)?
Tests use they and have been moved to one place

{
'no root element': 'dada',
'multiple root elements': '<div></div><div></div>'
}, function($prop) {
Copy link
Member

Choose a reason for hiding this comment

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

Calling this $prop too is confusing (since it is not the same $prop as in the description).
Maybe template or something.

expect(function() {
$compile('<p multi-root-elem></p>');
}).toThrowMinErr('$compile', 'tplrt', 'Template for directive \'multiRootElem\' must have exactly one root element. ');
inject(function($compile, $templateCache, $rootScope) {
Copy link
Member

Choose a reason for hiding this comment

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

Unused depedencies?

'comments + whitespace': ' <!-- oh hi --> <div>Hello World!</div> <!-- oh hi -->\n'
}, function($prop) {

inject(function($compile, $templateCache, $rootScope) {
Copy link
Member

Choose a reason for hiding this comment

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

Unused dependency?

var element;
expect(function() {
element = $compile('<p template></p>')($rootScope);
}).not.toThrowMinErr('$compile', 'tplrt', 'Template for directive \'template\' must have exactly one root element.');
Copy link
Member

Choose a reason for hiding this comment

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

.not.toThrow() is preferrable, since right now a small change in the message (or a typo) could render the test useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, but I think we should match against the error key (tplrt), because that is unlikely to change and we want to make sure that exact error is thrown.

Copy link
Member

Choose a reason for hiding this comment

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

I am talking about negative assertions only (i.e. with .not). Unless there is a reason (e.g. there is another error thrown that we can't prevent), I prefer to have as little info as possible (in order to make the assertion as strong as possible).

For example: .not.toThrow() is stronger than .not.toThrowMinErr('$compile') or .not.toThrowMinErr('$compile', 'tplrt').

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it.

@@ -2075,55 +2052,53 @@ describe('$compile', function() {
}
));

describe('replace and not exactly one root element', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Does it have to be the same description as above? What is the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one above is for template, this one is for templateUrl

@Narretz
Copy link
Contributor Author

Narretz commented Sep 26, 2016

Can you check / approve this one @gkalpak ?

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

LGTM

@Narretz Narretz force-pushed the refactor-compile-tests branch from cce6662 to 18d772b Compare October 7, 2016 20:12
@Narretz Narretz force-pushed the refactor-compile-tests branch from 18d772b to 1017b20 Compare October 9, 2016 18:20
@Narretz Narretz merged commit c22615c into angular:master Oct 14, 2016
Narretz added a commit that referenced this pull request Oct 14, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit that referenced this pull request Nov 23, 2016
petebacondarwin pushed a commit that referenced this pull request Nov 24, 2016
ellimist pushed a commit to ellimist/angular.js that referenced this pull request Mar 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants