Merge branch '28794-standardize-jasmine-test-describe-block-names-that-test-specific-methods' into 'master'

Resolve "Standardize jasmine test describe block names that test specific methods"

Closes #28794

See merge request !11137
This commit is contained in:
Filipa Lacerda 2017-05-08 15:28:53 +00:00
commit e98f12aff9
10 changed files with 53 additions and 26 deletions

View File

@ -29,6 +29,33 @@ browser and you will not have access to certain APIs, such as
which will have to be stubbed.
### Writing tests
When writing describe test blocks to test specific functions/methods,
please use the method name as the describe block name.
```javascript
// Good
describe('methodName', () => {
it('passes', () => {
expect(true).toEqual(true);
});
});
// Bad
describe('#methodName', () => {
it('passes', () => {
expect(true).toEqual(true);
});
});
// Bad
describe('.methodName', () => {
it('passes', () => {
expect(true).toEqual(true);
});
});
```
### Vue.js unit tests
See this [section][vue-test].

View File

@ -2,7 +2,7 @@ import BindInOut from '~/behaviors/bind_in_out';
import ClassSpecHelper from '../helpers/class_spec_helper';
describe('BindInOut', function () {
describe('.constructor', function () {
describe('constructor', function () {
beforeEach(function () {
this.in = {};
this.out = {};
@ -53,7 +53,7 @@ describe('BindInOut', function () {
});
});
describe('.addEvents', function () {
describe('addEvents', function () {
beforeEach(function () {
this.in = jasmine.createSpyObj('in', ['addEventListener']);
@ -79,7 +79,7 @@ describe('BindInOut', function () {
});
});
describe('.updateOut', function () {
describe('updateOut', function () {
beforeEach(function () {
this.in = { value: 'the-value' };
this.out = { textContent: 'not-the-value' };
@ -98,7 +98,7 @@ describe('BindInOut', function () {
});
});
describe('.removeEvents', function () {
describe('removeEvents', function () {
beforeEach(function () {
this.in = jasmine.createSpyObj('in', ['removeEventListener']);
this.updateOut = () => {};
@ -122,7 +122,7 @@ describe('BindInOut', function () {
});
});
describe('.initAll', function () {
describe('initAll', function () {
beforeEach(function () {
this.ins = [0, 1, 2];
this.instances = [];
@ -153,7 +153,7 @@ describe('BindInOut', function () {
});
});
describe('.init', function () {
describe('init', function () {
beforeEach(function () {
spyOn(BindInOut.prototype, 'addEvents').and.callFake(function () { return this; });
spyOn(BindInOut.prototype, 'updateOut').and.callFake(function () { return this; });

View File

@ -63,7 +63,7 @@ describe('TargetBranchDropdown', () => {
expect('change.branch').toHaveBeenTriggeredOn(dropdown.$dropdown);
});
describe('#dropdownData', () => {
describe('dropdownData', () => {
it('cache the refs', () => {
const refs = dropdown.cachedRefs;
dropdown.cachedRefs = null;
@ -88,7 +88,7 @@ describe('TargetBranchDropdown', () => {
});
});
describe('#setNewBranch', () => {
describe('setNewBranch', () => {
it('adds the new branch and select it', () => {
const branchName = 'new_branch';

View File

@ -32,7 +32,7 @@ describe('GLForm', () => {
});
});
describe('.setupAutosize', () => {
describe('setupAutosize', () => {
beforeEach((done) => {
this.glForm.setupAutosize();
setTimeout(() => {
@ -59,7 +59,7 @@ describe('GLForm', () => {
});
});
describe('.setHeightData', () => {
describe('setHeightData', () => {
beforeEach(() => {
spyOn($.prototype, 'data');
spyOn($.prototype, 'outerHeight').and.returnValue(200);
@ -75,7 +75,7 @@ describe('GLForm', () => {
});
});
describe('.destroyAutosize', () => {
describe('destroyAutosize', () => {
describe('when called', () => {
beforeEach(() => {
spyOn($.prototype, 'data');

View File

@ -3,7 +3,7 @@
require('./class_spec_helper');
describe('ClassSpecHelper', () => {
describe('.itShouldBeAStaticMethod', function () {
describe('itShouldBeAStaticMethod', function () {
beforeEach(() => {
class TestClass {
instanceMethod() { this.prop = 'val'; }

View File

@ -58,7 +58,7 @@ require('~/line_highlighter');
return expect(func).not.toThrow();
});
});
describe('#clickHandler', function() {
describe('clickHandler', function() {
it('handles clicking on a child icon element', function() {
var spy;
spy = spyOn(this["class"], 'setHash').and.callThrough();
@ -176,7 +176,7 @@ require('~/line_highlighter');
});
});
});
describe('#hashToRange', function() {
describe('hashToRange', function() {
beforeEach(function() {
return this.subject = this["class"].hashToRange;
});
@ -190,7 +190,7 @@ require('~/line_highlighter');
return expect(this.subject('#foo')).toEqual([null, null]);
});
});
describe('#highlightLine', function() {
describe('highlightLine', function() {
beforeEach(function() {
return this.subject = this["class"].highlightLine;
});
@ -203,7 +203,7 @@ require('~/line_highlighter');
return expect($('#LC13')).toHaveClass(this.css);
});
});
return describe('#setHash', function() {
return describe('setHash', function() {
beforeEach(function() {
return this.subject = this["class"].setHash;
});

View File

@ -47,7 +47,7 @@ require('vendor/jquery.scrollTo');
this.class.destroyPipelinesView();
});
describe('#activateTab', function () {
describe('activateTab', function () {
beforeEach(function () {
spyOn($, 'ajax').and.callFake(function () {});
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
@ -71,7 +71,7 @@ require('vendor/jquery.scrollTo');
});
});
describe('#opensInNewTab', function () {
describe('opensInNewTab', function () {
var tabUrl;
var windowTarget = '_blank';
@ -152,7 +152,7 @@ require('vendor/jquery.scrollTo');
});
});
describe('#setCurrentAction', function () {
describe('setCurrentAction', function () {
beforeEach(function () {
spyOn($, 'ajax').and.callFake(function () {});
this.subject = this.class.setCurrentAction;
@ -221,7 +221,7 @@ require('vendor/jquery.scrollTo');
});
});
describe('#tabShown', () => {
describe('tabShown', () => {
beforeEach(function () {
spyOn($, 'ajax').and.callFake(function (options) {
options.success({ html: '' });
@ -281,7 +281,7 @@ require('vendor/jquery.scrollTo');
});
});
describe('#loadDiff', function () {
describe('loadDiff', function () {
it('requires an absolute pathname', function () {
spyOn($, 'ajax').and.callFake(function (options) {
expect(options.url).toEqual('/foo/bar/merge_requests/1/diffs.json');

View File

@ -13,7 +13,7 @@ require('~/shortcuts_issuable');
document.querySelector('.js-new-note-form').classList.add('js-main-target-form');
this.shortcut = new ShortcutsIssuable();
});
describe('#replyWithSelectedText', function() {
describe('replyWithSelectedText', function() {
var stubSelection;
// Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML.
stubSelection = function(html) {

View File

@ -3,7 +3,7 @@ const VersionCheckImage = require('~/version_check_image');
require('jquery');
describe('VersionCheckImage', function () {
describe('.bindErrorEvent', function () {
describe('bindErrorEvent', function () {
ClassSpecHelper.itShouldBeAStaticMethod(VersionCheckImage, 'bindErrorEvent');
beforeEach(function () {

View File

@ -22,7 +22,7 @@ require('~/visibility_select');
spyOn(Element.prototype, 'querySelector').and.callFake(selector => mockElements[selector]);
});
describe('#constructor', function () {
describe('constructor', function () {
beforeEach(function () {
this.visibilitySelect = new VisibilitySelect(mockElements.container);
});
@ -48,7 +48,7 @@ require('~/visibility_select');
});
});
describe('#init', function () {
describe('init', function () {
describe('if there is a select', function () {
beforeEach(function () {
this.visibilitySelect = new VisibilitySelect(mockElements.container);
@ -85,7 +85,7 @@ require('~/visibility_select');
});
});
describe('#updateHelpText', function () {
describe('updateHelpText', function () {
beforeEach(function () {
this.visibilitySelect = new VisibilitySelect(mockElements.container);
this.visibilitySelect.init();