javascript - How to ensure DRY code in Jasmine Unit tests? -
if have popover say, , want test it:
- being created
- being manipulated
- being destroyed
it beneficial have declared in 1 place (tucked inside "describe"), can shared across "its".
should 1 share things between tests? i.e test2 relies on test1 being run first? best way jasmine?
it`s bad thing rely test order. share things between tests can have way set state of object. assume pseudo code below:
var popover = getpopover({state:'init'}); //checking init state ... //other test starting var popover = getpopover({state:'manipulated'}); //checking state so main idea able init object @ state need. note, if it's not code perform initialization , not going need reuse much, can hardcode state setup every test. sure, it's not dry, benefit tests can read, without references other methods. sometime it's thing, depends.
also, can use beforeeach , aftereach setup , teardown before , after every test( it's describe level thing ). 1 of preferred ways perform state initialization , cleanup.
Comments
Post a Comment