-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
reorganize and refactor common buildRegion unit tests #3548
Conversation
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.
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}); |
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.
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); |
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.
nit-pick , BarRegion
this.view.addRegion(_.uniqueId('region_'),this.BarRegion); | ||
}.bind(this); | ||
buildRegion = function() { | ||
view.addRegion(_.uniqueId('region_'),BarRegion); |
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.
same here. linter must not be very strict 😞
beforeEach(function() { | ||
this.BarRegion = Marionette.Region.extend(); | ||
BarRegion = Region.extend(); |
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.
the redefinition seems unnecessary
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.
The above assignment of BarRegion
has an el assignment, which would make these tests fail. Is there a better way to handle the reassignment?
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.
how about BazRegion
beforeEach(function() { | ||
this.region = this.view.addRegion(_.uniqueId('region_'),this.barRegion); | ||
region = view.addRegion(_.uniqueId('region_'),barRegion); |
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.
last one , barRegion
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.
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}); |
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.
these don't seem necessary
}); | ||
|
||
describe('with `el` also defined', function() { | ||
let baseDefinition; |
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.
some of these only need to be let
s 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; |
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.
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); |
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.
,
}); | ||
}); | ||
}); | ||
|
||
describe('when el is an empty jQuery object', function() { | ||
let el; | ||
let definition; | ||
let buildRegion; |
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.
as below I think buildRegion
is the only necessary let, the others can be const
inside the beforeEach
s
e348b1f
to
831e288
Compare
831e288
to
a4d771d
Compare
Proposed changes
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