Commit e98f12af authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch...

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
parents 11ff9fc6 06455d2f
...@@ -29,6 +29,33 @@ browser and you will not have access to certain APIs, such as ...@@ -29,6 +29,33 @@ browser and you will not have access to certain APIs, such as
which will have to be stubbed. which will have to be stubbed.
### Writing tests ### 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 ### Vue.js unit tests
See this [section][vue-test]. See this [section][vue-test].
......
...@@ -2,7 +2,7 @@ import BindInOut from '~/behaviors/bind_in_out'; ...@@ -2,7 +2,7 @@ import BindInOut from '~/behaviors/bind_in_out';
import ClassSpecHelper from '../helpers/class_spec_helper'; import ClassSpecHelper from '../helpers/class_spec_helper';
describe('BindInOut', function () { describe('BindInOut', function () {
describe('.constructor', function () { describe('constructor', function () {
beforeEach(function () { beforeEach(function () {
this.in = {}; this.in = {};
this.out = {}; this.out = {};
...@@ -53,7 +53,7 @@ describe('BindInOut', function () { ...@@ -53,7 +53,7 @@ describe('BindInOut', function () {
}); });
}); });
describe('.addEvents', function () { describe('addEvents', function () {
beforeEach(function () { beforeEach(function () {
this.in = jasmine.createSpyObj('in', ['addEventListener']); this.in = jasmine.createSpyObj('in', ['addEventListener']);
...@@ -79,7 +79,7 @@ describe('BindInOut', function () { ...@@ -79,7 +79,7 @@ describe('BindInOut', function () {
}); });
}); });
describe('.updateOut', function () { describe('updateOut', function () {
beforeEach(function () { beforeEach(function () {
this.in = { value: 'the-value' }; this.in = { value: 'the-value' };
this.out = { textContent: 'not-the-value' }; this.out = { textContent: 'not-the-value' };
...@@ -98,7 +98,7 @@ describe('BindInOut', function () { ...@@ -98,7 +98,7 @@ describe('BindInOut', function () {
}); });
}); });
describe('.removeEvents', function () { describe('removeEvents', function () {
beforeEach(function () { beforeEach(function () {
this.in = jasmine.createSpyObj('in', ['removeEventListener']); this.in = jasmine.createSpyObj('in', ['removeEventListener']);
this.updateOut = () => {}; this.updateOut = () => {};
...@@ -122,7 +122,7 @@ describe('BindInOut', function () { ...@@ -122,7 +122,7 @@ describe('BindInOut', function () {
}); });
}); });
describe('.initAll', function () { describe('initAll', function () {
beforeEach(function () { beforeEach(function () {
this.ins = [0, 1, 2]; this.ins = [0, 1, 2];
this.instances = []; this.instances = [];
...@@ -153,7 +153,7 @@ describe('BindInOut', function () { ...@@ -153,7 +153,7 @@ describe('BindInOut', function () {
}); });
}); });
describe('.init', function () { describe('init', function () {
beforeEach(function () { beforeEach(function () {
spyOn(BindInOut.prototype, 'addEvents').and.callFake(function () { return this; }); spyOn(BindInOut.prototype, 'addEvents').and.callFake(function () { return this; });
spyOn(BindInOut.prototype, 'updateOut').and.callFake(function () { return this; }); spyOn(BindInOut.prototype, 'updateOut').and.callFake(function () { return this; });
......
...@@ -63,7 +63,7 @@ describe('TargetBranchDropdown', () => { ...@@ -63,7 +63,7 @@ describe('TargetBranchDropdown', () => {
expect('change.branch').toHaveBeenTriggeredOn(dropdown.$dropdown); expect('change.branch').toHaveBeenTriggeredOn(dropdown.$dropdown);
}); });
describe('#dropdownData', () => { describe('dropdownData', () => {
it('cache the refs', () => { it('cache the refs', () => {
const refs = dropdown.cachedRefs; const refs = dropdown.cachedRefs;
dropdown.cachedRefs = null; dropdown.cachedRefs = null;
...@@ -88,7 +88,7 @@ describe('TargetBranchDropdown', () => { ...@@ -88,7 +88,7 @@ describe('TargetBranchDropdown', () => {
}); });
}); });
describe('#setNewBranch', () => { describe('setNewBranch', () => {
it('adds the new branch and select it', () => { it('adds the new branch and select it', () => {
const branchName = 'new_branch'; const branchName = 'new_branch';
......
...@@ -32,7 +32,7 @@ describe('GLForm', () => { ...@@ -32,7 +32,7 @@ describe('GLForm', () => {
}); });
}); });
describe('.setupAutosize', () => { describe('setupAutosize', () => {
beforeEach((done) => { beforeEach((done) => {
this.glForm.setupAutosize(); this.glForm.setupAutosize();
setTimeout(() => { setTimeout(() => {
...@@ -59,7 +59,7 @@ describe('GLForm', () => { ...@@ -59,7 +59,7 @@ describe('GLForm', () => {
}); });
}); });
describe('.setHeightData', () => { describe('setHeightData', () => {
beforeEach(() => { beforeEach(() => {
spyOn($.prototype, 'data'); spyOn($.prototype, 'data');
spyOn($.prototype, 'outerHeight').and.returnValue(200); spyOn($.prototype, 'outerHeight').and.returnValue(200);
...@@ -75,7 +75,7 @@ describe('GLForm', () => { ...@@ -75,7 +75,7 @@ describe('GLForm', () => {
}); });
}); });
describe('.destroyAutosize', () => { describe('destroyAutosize', () => {
describe('when called', () => { describe('when called', () => {
beforeEach(() => { beforeEach(() => {
spyOn($.prototype, 'data'); spyOn($.prototype, 'data');
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require('./class_spec_helper'); require('./class_spec_helper');
describe('ClassSpecHelper', () => { describe('ClassSpecHelper', () => {
describe('.itShouldBeAStaticMethod', function () { describe('itShouldBeAStaticMethod', function () {
beforeEach(() => { beforeEach(() => {
class TestClass { class TestClass {
instanceMethod() { this.prop = 'val'; } instanceMethod() { this.prop = 'val'; }
......
...@@ -58,7 +58,7 @@ require('~/line_highlighter'); ...@@ -58,7 +58,7 @@ require('~/line_highlighter');
return expect(func).not.toThrow(); return expect(func).not.toThrow();
}); });
}); });
describe('#clickHandler', function() { describe('clickHandler', function() {
it('handles clicking on a child icon element', function() { it('handles clicking on a child icon element', function() {
var spy; var spy;
spy = spyOn(this["class"], 'setHash').and.callThrough(); spy = spyOn(this["class"], 'setHash').and.callThrough();
...@@ -176,7 +176,7 @@ require('~/line_highlighter'); ...@@ -176,7 +176,7 @@ require('~/line_highlighter');
}); });
}); });
}); });
describe('#hashToRange', function() { describe('hashToRange', function() {
beforeEach(function() { beforeEach(function() {
return this.subject = this["class"].hashToRange; return this.subject = this["class"].hashToRange;
}); });
...@@ -190,7 +190,7 @@ require('~/line_highlighter'); ...@@ -190,7 +190,7 @@ require('~/line_highlighter');
return expect(this.subject('#foo')).toEqual([null, null]); return expect(this.subject('#foo')).toEqual([null, null]);
}); });
}); });
describe('#highlightLine', function() { describe('highlightLine', function() {
beforeEach(function() { beforeEach(function() {
return this.subject = this["class"].highlightLine; return this.subject = this["class"].highlightLine;
}); });
...@@ -203,7 +203,7 @@ require('~/line_highlighter'); ...@@ -203,7 +203,7 @@ require('~/line_highlighter');
return expect($('#LC13')).toHaveClass(this.css); return expect($('#LC13')).toHaveClass(this.css);
}); });
}); });
return describe('#setHash', function() { return describe('setHash', function() {
beforeEach(function() { beforeEach(function() {
return this.subject = this["class"].setHash; return this.subject = this["class"].setHash;
}); });
......
...@@ -47,7 +47,7 @@ require('vendor/jquery.scrollTo'); ...@@ -47,7 +47,7 @@ require('vendor/jquery.scrollTo');
this.class.destroyPipelinesView(); this.class.destroyPipelinesView();
}); });
describe('#activateTab', function () { describe('activateTab', function () {
beforeEach(function () { beforeEach(function () {
spyOn($, 'ajax').and.callFake(function () {}); spyOn($, 'ajax').and.callFake(function () {});
loadFixtures('merge_requests/merge_request_with_task_list.html.raw'); loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
...@@ -71,7 +71,7 @@ require('vendor/jquery.scrollTo'); ...@@ -71,7 +71,7 @@ require('vendor/jquery.scrollTo');
}); });
}); });
describe('#opensInNewTab', function () { describe('opensInNewTab', function () {
var tabUrl; var tabUrl;
var windowTarget = '_blank'; var windowTarget = '_blank';
...@@ -152,7 +152,7 @@ require('vendor/jquery.scrollTo'); ...@@ -152,7 +152,7 @@ require('vendor/jquery.scrollTo');
}); });
}); });
describe('#setCurrentAction', function () { describe('setCurrentAction', function () {
beforeEach(function () { beforeEach(function () {
spyOn($, 'ajax').and.callFake(function () {}); spyOn($, 'ajax').and.callFake(function () {});
this.subject = this.class.setCurrentAction; this.subject = this.class.setCurrentAction;
...@@ -221,7 +221,7 @@ require('vendor/jquery.scrollTo'); ...@@ -221,7 +221,7 @@ require('vendor/jquery.scrollTo');
}); });
}); });
describe('#tabShown', () => { describe('tabShown', () => {
beforeEach(function () { beforeEach(function () {
spyOn($, 'ajax').and.callFake(function (options) { spyOn($, 'ajax').and.callFake(function (options) {
options.success({ html: '' }); options.success({ html: '' });
...@@ -281,7 +281,7 @@ require('vendor/jquery.scrollTo'); ...@@ -281,7 +281,7 @@ require('vendor/jquery.scrollTo');
}); });
}); });
describe('#loadDiff', function () { describe('loadDiff', function () {
it('requires an absolute pathname', function () { it('requires an absolute pathname', function () {
spyOn($, 'ajax').and.callFake(function (options) { spyOn($, 'ajax').and.callFake(function (options) {
expect(options.url).toEqual('/foo/bar/merge_requests/1/diffs.json'); expect(options.url).toEqual('/foo/bar/merge_requests/1/diffs.json');
......
...@@ -13,7 +13,7 @@ require('~/shortcuts_issuable'); ...@@ -13,7 +13,7 @@ require('~/shortcuts_issuable');
document.querySelector('.js-new-note-form').classList.add('js-main-target-form'); document.querySelector('.js-new-note-form').classList.add('js-main-target-form');
this.shortcut = new ShortcutsIssuable(); this.shortcut = new ShortcutsIssuable();
}); });
describe('#replyWithSelectedText', function() { describe('replyWithSelectedText', function() {
var stubSelection; var stubSelection;
// Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML. // Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML.
stubSelection = function(html) { stubSelection = function(html) {
......
...@@ -3,7 +3,7 @@ const VersionCheckImage = require('~/version_check_image'); ...@@ -3,7 +3,7 @@ const VersionCheckImage = require('~/version_check_image');
require('jquery'); require('jquery');
describe('VersionCheckImage', function () { describe('VersionCheckImage', function () {
describe('.bindErrorEvent', function () { describe('bindErrorEvent', function () {
ClassSpecHelper.itShouldBeAStaticMethod(VersionCheckImage, 'bindErrorEvent'); ClassSpecHelper.itShouldBeAStaticMethod(VersionCheckImage, 'bindErrorEvent');
beforeEach(function () { beforeEach(function () {
......
...@@ -22,7 +22,7 @@ require('~/visibility_select'); ...@@ -22,7 +22,7 @@ require('~/visibility_select');
spyOn(Element.prototype, 'querySelector').and.callFake(selector => mockElements[selector]); spyOn(Element.prototype, 'querySelector').and.callFake(selector => mockElements[selector]);
}); });
describe('#constructor', function () { describe('constructor', function () {
beforeEach(function () { beforeEach(function () {
this.visibilitySelect = new VisibilitySelect(mockElements.container); this.visibilitySelect = new VisibilitySelect(mockElements.container);
}); });
...@@ -48,7 +48,7 @@ require('~/visibility_select'); ...@@ -48,7 +48,7 @@ require('~/visibility_select');
}); });
}); });
describe('#init', function () { describe('init', function () {
describe('if there is a select', function () { describe('if there is a select', function () {
beforeEach(function () { beforeEach(function () {
this.visibilitySelect = new VisibilitySelect(mockElements.container); this.visibilitySelect = new VisibilitySelect(mockElements.container);
...@@ -85,7 +85,7 @@ require('~/visibility_select'); ...@@ -85,7 +85,7 @@ require('~/visibility_select');
}); });
}); });
describe('#updateHelpText', function () { describe('updateHelpText', function () {
beforeEach(function () { beforeEach(function () {
this.visibilitySelect = new VisibilitySelect(mockElements.container); this.visibilitySelect = new VisibilitySelect(mockElements.container);
this.visibilitySelect.init(); this.visibilitySelect.init();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment