Jasmine: one match for "this" or more?

Is it correct to have several matches for one “this” in Jasmine’s tests or will they interfere with each other?

I want to combine these tests into one:

var mapper = ......... ; it('should be reviewed if not admin and language not set', inject(function() { scope.globals.isAdmin = false; scope.globals.language = ''; mapper.updatedOn.setYear(2013); expect(scope.isReviewed(mapper)).toBe(true); })); it('should disregard mapper date if not admin and language not set', inject(function() { scope.globals.isAdmin = false; scope.globals.language = ''; mapper.updatedOn.setYear(2015); expect(scope.isReviewed(mapper)).toBe(true); })); it('should be reviewed if admin and mapper is older', inject(function() { scope.globals.isAdmin = true; scope.globals.language = ''; mapper.updatedOn.setYear(2013); expect(scope.isReviewed(mapper)).toBe(true); })); it('should be not reviewed if admin and mapper is newer', inject(function() { scope.globals.isAdmin = true; scope.globals.language = ''; mapper.updatedOn.setYear(2015); expect(scope.isReviewed(mapper)).toBe(false); })); it('should be reviewed if not admin, language is set and mapper is older', inject(function() { scope.globals.isAdmin = false; scope.globals.language = 'de'; mapper.updatedOn.setYear(2013); expect(scope.isReviewed(mapper)).toBe(true); })); it('should be not reviewed if not admin, language is set and mapper is newer', inject(function() { scope.globals.isAdmin = false; scope.globals.language = 'de'; mapper.updatedOn.setYear(2015); expect(scope.isReviewed(mapper)).toBe(false); })); 

Is this possible / reasonable?

+4
source share
2 answers

You can have as many test statements as you want. But for many, it is difficult to read when these tests fail. The reason is that you need to scan dozens of lines to find out what is wrong, instead of just seeing that 'should be not reviewed if not admin, language is set and mapper is newer' does not work.

Btw. in your case, you could write a helper function so that you don't have such a large template:

 var admin = true; var notAdmin = false init(isAdmin, language, year) { scope.globals.isAdmin = isAdmin; scope.globals.language = language; mapper.updatedOn.setYear(year); } it('should be not reviewed if not admin, language is set and mapper is newer', inject(function() { init(admin, 'de', 2015) expect(scope.isReviewed(mapper)).toBe(false); })); 
+5
source

I would say that this is not about the "number of expectations" for him. But from the amount of "number of behaviors" for him. If testing one behavior requires more than one, use more. But do not test several aspects that do not belong together in the same test case.

Test one behavior in each block, just like you, and use the suggestion of Andreas Keberles to use a helper function.

+2
source

Source: https://habr.com/ru/post/1479572/


All Articles