| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import chai from 'chai' |
||
| 15 | describe('coreUtils.array', function() { |
||
| 16 | |||
| 17 | var arr = [{'test': 'val'}, {'test2': 'val2'}]; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * coreUtils.array.find |
||
| 21 | * |
||
| 22 | */ |
||
| 23 | it('coreUtils.array.find()', function() { |
||
| 24 | var result = coreUtils.array.find(arr, 'test', 'val'); |
||
| 25 | chai.expect(result).to.be.a('array') |
||
| 26 | chai.expect(result.length).to.equal(1) |
||
| 27 | chai.expect(result[0]).to.equal(0) |
||
| 28 | var result2 = coreUtils.array.find(arr, 'test2', 'val2'); |
||
| 29 | chai.expect(result2).to.be.a('array') |
||
| 30 | chai.expect(result2.length).to.equal(1) |
||
| 31 | chai.expect(result2[0]).to.equal(1) |
||
| 32 | }); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * coreUtils.array.filter |
||
| 36 | * |
||
| 37 | */ |
||
| 38 | it('coreUtils.array.filter()', function() { |
||
| 39 | var result = coreUtils.array.filter(arr, 'test', 'val'); |
||
| 40 | chai.expect(result).to.be.a('array') |
||
| 41 | chai.expect(result.length).to.equal(1) |
||
| 42 | chai.expect(result[0]).to.have.test |
||
| 43 | chai.expect(result[0].test).to.equal('val') |
||
| 44 | }); |
||
| 45 | |||
| 46 | /** |
||
| 47 | * coreUtils.array.removeByAttr |
||
| 48 | * |
||
| 49 | */ |
||
| 50 | it('coreUtils.array.removeByAttr()', function() { |
||
| 51 | var result = coreUtils.array.removeByAttr(arr, 'test2', 'val2'); |
||
| 52 | chai.expect(result).to.be.a('array') |
||
| 53 | chai.expect(result.length).to.equal(1) |
||
| 54 | chai.expect(result[0]).to.have.test |
||
| 55 | chai.expect(result[0].test).to.equal('val') |
||
| 56 | }); |
||
| 57 | |||
| 58 | /** |
||
| 59 | * coreUtils.array.contains |
||
| 60 | * |
||
| 61 | */ |
||
| 62 | it('coreUtils.array.contains()', function() { |
||
| 63 | var testArray = ["test0", "test1", "test2"]; |
||
| 64 | var result = coreUtils.array.contains(testArray, 'test1'); |
||
| 65 | chai.expect(result).to.be.true |
||
| 66 | var result2 = coreUtils.array.contains(testArray, 'test3'); |
||
| 67 | chai.expect(result2).to.be.false |
||
| 68 | }); |
||
| 69 | |||
| 70 | }); |
||
| 71 |