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

reorganize and refactor common buildRegion unit tests #3548

Merged
merged 1 commit into from
Nov 26, 2017

Conversation

wesmangum
Copy link
Contributor

Proposed changes

  • Reorganize tests to match order of codebase
  • Import dependencies to move away from using global ones
  • Use let in favor of this in beforeEach

Link to the issue: #3248

This pr is a small part of the work to refactor the whole unit tests directory. Merging this issue should keep #3248 open

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e22f0cb on wesmangum:tests/common/buildRegion into 2b2bee3 on marionettejs:next.

Copy link
Member

@paulfalgout paulfalgout left a comment

Choose a reason for hiding this comment

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

Let's not instantiate regions unless they're tested and let's move any let that is only used inside the beforeEach to be const defined in them

this.fooSelector = '#foo-region';
this.fooRegion = new this.DefaultRegionClass({el: this.fooSelector});
fooSelector = '#foo-region';
new DefaultRegionClass({el: fooSelector});
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what this line is doing. I suspect the this.fooRegion was removed, but the beforeEach wasn't cleaned up. if we're not using this, there's no reason to keep it around.

beforeEach(function() {
this.region = this.view.addRegion(_.uniqueId('region_'),this.BarRegion);
region = view.addRegion(_.uniqueId('region_'),BarRegion);
Copy link
Member

Choose a reason for hiding this comment

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

nit-pick , BarRegion

this.view.addRegion(_.uniqueId('region_'),this.BarRegion);
}.bind(this);
buildRegion = function() {
view.addRegion(_.uniqueId('region_'),BarRegion);
Copy link
Member

Choose a reason for hiding this comment

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

same here. linter must not be very strict 😞

beforeEach(function() {
this.BarRegion = Marionette.Region.extend();
BarRegion = Region.extend();
Copy link
Member

Choose a reason for hiding this comment

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

the redefinition seems unnecessary

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 above assignment of BarRegion has an el assignment, which would make these tests fail. Is there a better way to handle the reassignment?

Copy link
Member

Choose a reason for hiding this comment

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

how about BazRegion

beforeEach(function() {
this.region = this.view.addRegion(_.uniqueId('region_'),this.barRegion);
region = view.addRegion(_.uniqueId('region_'),barRegion);
Copy link
Member

Choose a reason for hiding this comment

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

last one , barRegion

Copy link
Member

Choose a reason for hiding this comment

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

in this case maybe we can move the instantiation down inside this beforeEach it seems specific to this describe rather than all of them.. in fact this can probably just be , new BarRegion()

region2Definition = _.defaults({el: el}, baseDefinition);
region3Definition = _.defaults({el: $el}, baseDefinition);

new BazRegion({el: fooSelector});
Copy link
Member

Choose a reason for hiding this comment

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

these don't seem necessary

});

describe('with `el` also defined', function() {
let baseDefinition;
Copy link
Member

Choose a reason for hiding this comment

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

some of these only need to be lets if they're tested outside of the beforeEach if it's just a variable used within a single function let's keep it const

});
});

describe('with `regionClass` defined', function() {
let $el;
Copy link
Member

Choose a reason for hiding this comment

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

these el and $el are only used inside the next describe block.. let's move them there

this.view.addRegion(_.uniqueId('region_'),this.definition);
}.bind(this);
buildRegion = function() {
view.addRegion(_.uniqueId('region_'),definition);
Copy link
Member

Choose a reason for hiding this comment

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

,

});
});
});

describe('when el is an empty jQuery object', function() {
let el;
let definition;
let buildRegion;
Copy link
Member

Choose a reason for hiding this comment

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

as below I think buildRegion is the only necessary let, the others can be const inside the beforeEachs

@wesmangum wesmangum force-pushed the tests/common/buildRegion branch 2 times, most recently from e348b1f to 831e288 Compare November 16, 2017 18:07
@coveralls
Copy link

Coverage Status

Coverage decreased (-68.04%) to 31.957% when pulling a4d771d on wesmangum:tests/common/buildRegion into 5813ed2 on marionettejs:next.

@coveralls
Copy link

Coverage Status

Coverage decreased (-68.04%) to 31.957% when pulling a4d771d on wesmangum:tests/common/buildRegion into 5813ed2 on marionettejs:next.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling a4d771d on wesmangum:tests/common/buildRegion into 5813ed2 on marionettejs:next.

@paulfalgout paulfalgout merged commit 9e1398e into marionettejs:next Nov 26, 2017
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.

None yet

3 participants