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
Narretz merged 1 commit into
angular:masterfrom
Narretz:refactor-compile-tests
Oct 14, 2016
Merged

refactor(compileSpec): make tests consistent#15141
Narretz merged 1 commit into
angular:masterfrom
Narretz:refactor-compile-tests

Conversation

@Narretz

@Narretz Narretz commented Sep 15, 2016

Copy link
Copy Markdown
Contributor

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

Comment thread test/ng/compileSpec.js Outdated
{
'no root element': 'dada',
'multiple root elements': '<div></div><div></div>'
}, function($prop) {

Copy link
Copy Markdown
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.

Comment thread test/ng/compileSpec.js Outdated
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unused depedencies?

Comment thread test/ng/compileSpec.js Outdated
'comments + whitespace': ' <!-- oh hi --> <div>Hello World!</div> <!-- oh hi -->\n'
}, function($prop) {

inject(function($compile, $templateCache, $rootScope) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unused dependency?

Comment thread test/ng/compileSpec.js Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread test/ng/compileSpec.js
}
));

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

Copy link
Copy Markdown
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
Copy Markdown
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

Narretz commented Sep 26, 2016

Copy link
Copy Markdown
Contributor Author

Can you check / approve this one @gkalpak ?

@gkalpak gkalpak left a comment

Copy link
Copy Markdown
Member

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