Commit 28c7f242 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '194234-migrate-spec-javascripts-droplab-to-jest-3' into 'master'

Move droplab hook_spec tests to jest

See merge request gitlab-org/gitlab!32764
parents 60fb5e8d 4ecd8b18
import Hook from '~/droplab/hook';
import DropDown from '~/droplab/drop_down';
jest.mock('~/droplab/drop_down', () => jest.fn());
describe('Hook', () => {
let testContext;
beforeEach(() => {
testContext = {};
});
describe('class constructor', () => {
beforeEach(() => {
testContext.trigger = { id: 'id' };
testContext.list = {};
testContext.plugins = {};
testContext.config = {};
testContext.hook = new Hook(
testContext.trigger,
testContext.list,
testContext.plugins,
testContext.config,
);
});
it('should set .trigger', () => {
expect(testContext.hook.trigger).toBe(testContext.trigger);
});
it('should set .list', () => {
expect(testContext.hook.list).toEqual({});
});
it('should call DropDown constructor', () => {
expect(DropDown).toHaveBeenCalledWith(testContext.list, testContext.config);
});
it('should set .type', () => {
expect(testContext.hook.type).toBe('Hook');
});
it('should set .event', () => {
expect(testContext.hook.event).toBe('click');
});
it('should set .plugins', () => {
expect(testContext.hook.plugins).toBe(testContext.plugins);
});
it('should set .config', () => {
expect(testContext.hook.config).toBe(testContext.config);
});
it('should set .id', () => {
expect(testContext.hook.id).toBe(testContext.trigger.id);
});
describe('if config argument is undefined', () => {
beforeEach(() => {
testContext.config = undefined;
testContext.hook = new Hook(
testContext.trigger,
testContext.list,
testContext.plugins,
testContext.config,
);
});
it('should set .config to an empty object', () => {
expect(testContext.hook.config).toEqual({});
});
});
describe('if plugins argument is undefined', () => {
beforeEach(() => {
testContext.plugins = undefined;
testContext.hook = new Hook(
testContext.trigger,
testContext.list,
testContext.plugins,
testContext.config,
);
});
it('should set .plugins to an empty array', () => {
expect(testContext.hook.plugins).toEqual([]);
});
});
});
});
import Hook from '~/droplab/hook';
describe('Hook', function() {
describe('class constructor', function() {
beforeEach(function() {
this.trigger = { id: 'id' };
this.list = {};
this.plugins = {};
this.config = {};
this.dropdown = {};
this.dropdownConstructor = spyOnDependency(Hook, 'DropDown').and.returnValue(this.dropdown);
this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
});
it('should set .trigger', function() {
expect(this.hook.trigger).toBe(this.trigger);
});
it('should set .list', function() {
expect(this.hook.list).toBe(this.dropdown);
});
it('should call DropDown constructor', function() {
expect(this.dropdownConstructor).toHaveBeenCalledWith(this.list, this.config);
});
it('should set .type', function() {
expect(this.hook.type).toBe('Hook');
});
it('should set .event', function() {
expect(this.hook.event).toBe('click');
});
it('should set .plugins', function() {
expect(this.hook.plugins).toBe(this.plugins);
});
it('should set .config', function() {
expect(this.hook.config).toBe(this.config);
});
it('should set .id', function() {
expect(this.hook.id).toBe(this.trigger.id);
});
describe('if config argument is undefined', function() {
beforeEach(function() {
this.config = undefined;
this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
});
it('should set .config to an empty object', function() {
expect(this.hook.config).toEqual({});
});
});
describe('if plugins argument is undefined', function() {
beforeEach(function() {
this.plugins = undefined;
this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
});
it('should set .plugins to an empty array', function() {
expect(this.hook.plugins).toEqual([]);
});
});
});
});
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