is not found', function() {
+ expect(() => {
+ const div = document.createElement('div');
+ div.innerHTML = `
`;
+ new FileUploader(div);
+ }).toThrowError(TypeError, 'Cannot find the file names container.');
});
it('should set default options', function() {
- expect(instance.options).to.deep.equal({
+ expect(flattenOptions(instance.options)).toEqual({
selectorInit: '[data-file]',
selectorInput: 'input[type="file"].bx--file-input',
selectorContainer: '[data-file-container]',
@@ -47,20 +64,20 @@ describe('File Uploader', function() {
it('should access container element', function() {
const container = element.querySelector('[data-file-container]');
- expect(instance.container).to.equal(container);
+ expect(instance.container).toBe(container);
});
it('should access the input element', function() {
const input = element.querySelector('input');
- expect(instance.input).to.equal(input);
+ expect(instance.input).toBe(input);
});
it('should access id for input', function() {
const input = element.querySelector('input');
- expect(instance.inputId).to.equal(input.id);
+ expect(instance.inputId).toBe(input.id);
});
- after(function() {
+ afterAll(function() {
instance.release();
document.body.removeChild(wrapper);
});
@@ -86,7 +103,7 @@ describe('File Uploader', function() {
document.body.appendChild(div);
const nameElement = document.querySelector('.bx--file-filename');
- expect(nameElement.innerHTML).to.equal('testName');
+ expect(nameElement.innerHTML).toBe('testName');
document.body.removeChild(div);
});
@@ -98,7 +115,7 @@ describe('File Uploader', function() {
document.body.appendChild(div);
const idElement = document.querySelector('.bx--file__state-container');
- expect(idElement.dataset.for).to.equal('testId');
+ expect(idElement.dataset.for).toBe('testId');
document.body.removeChild(div);
});
@@ -110,7 +127,7 @@ describe('File Uploader', function() {
document.body.appendChild(div);
const uploadElement = document.querySelector('[data-loading]');
- expect(uploadElement.classList.contains('bx--loading')).to.be.true;
+ expect(uploadElement.classList.contains('bx--loading')).toBe(true);
document.body.removeChild(div);
});
@@ -128,7 +145,7 @@ describe('File Uploader', function() {
.trim()
.split(/\s+/)
.indexOf('bx--file-close') >= 0
- ).to.be.true;
+ ).toBe(true);
document.body.removeChild(div);
});
@@ -146,7 +163,7 @@ describe('File Uploader', function() {
.trim()
.split(/\s+/)
.indexOf('bx--file-complete') >= 0
- ).to.be.true;
+ ).toBe(true);
document.body.removeChild(div);
});
@@ -173,17 +190,16 @@ describe('File Uploader', function() {
it('should throw if element param is not given', function() {
expect(() => {
instance._removeState(document.createTextNode(''));
- }).to.throw(Error);
+ }).toThrowError(Error);
});
it('should be called', function() {
const parentEl = document.createElement('div');
const childEl = document.createElement('span');
parentEl.appendChild(childEl);
- const spy = sinon.spy(instance, '_removeState');
+ spyOn(instance, '_removeState');
instance._removeState(parentEl);
- expect(spy).to.have.been.called;
- spy.restore();
+ expect(instance._removeState).toHaveBeenCalled();
});
it('should remove the firstChild of given element', function() {
@@ -193,7 +209,7 @@ describe('File Uploader', function() {
parentEl.appendChild(childEl);
document.body.appendChild(parentEl);
instance._removeState(parentEl);
- expect(document.querySelector('.foo').firstChild).to.be.a('null');
+ expect(document.querySelector('.foo').firstChild).toBe(null);
document.body.removeChild(parentEl);
});
@@ -219,7 +235,7 @@ describe('File Uploader', function() {
it('should throw if stateContainers are empty', function() {
expect(() => {
instance._getStateContainers();
- }).to.throw(Error);
+ }).toThrowError(Error);
});
it('should throw if id for input[type="file"] does not equal [data-for] attribute on state container', function() {
@@ -227,36 +243,36 @@ describe('File Uploader', function() {
instance.container.insertAdjacentHTML('beforeend', filenameElement);
expect(() => {
instance._getStateContainers();
- }).to.throw(Error);
+ }).toThrowError(Error);
});
it('should be called', function() {
const filenameElement = instance._filenamesHTML('name', instance.inputId);
instance.container.insertAdjacentHTML('beforeend', filenameElement);
- const spy = sinon.spy(instance, '_getStateContainers');
+ spyOn(instance, '_getStateContainers');
instance._getStateContainers();
- expect(spy).to.have.been.called;
+ expect(instance._getStateContainers).toHaveBeenCalled();
});
it('should return an array', function() {
const filenameElement = instance._filenamesHTML('name', instance.inputId);
instance.container.insertAdjacentHTML('beforeend', filenameElement);
const array = instance._getStateContainers();
- expect(array).to.be.a('array');
+ expect(Array.isArray(array)).toBe(true);
});
it('should have a length', function() {
const filenameElement = instance._filenamesHTML('name', instance.inputId);
instance.container.insertAdjacentHTML('beforeend', filenameElement);
const array = instance._getStateContainers();
- expect(array.length).to.equal(1);
+ expect(array.length).toBe(1);
});
it('should have an empty stateContainer', function() {
const filenameElement = instance._filenamesHTML('name', instance.inputId);
instance.container.insertAdjacentHTML('beforeend', filenameElement);
const stateContainer = document.querySelector('.bx--file__state-container');
- expect(stateContainer.innerHTML).to.equal('');
+ expect(stateContainer.innerHTML).toBe('');
});
afterEach(function() {
@@ -270,7 +286,7 @@ describe('File Uploader', function() {
let element;
let wrapper;
- before(function() {
+ beforeAll(function() {
wrapper = document.createElement('div');
wrapper.innerHTML = HTML;
document.body.appendChild(wrapper);
@@ -279,13 +295,13 @@ describe('File Uploader', function() {
});
it('should be called on input change event', function() {
- const spy = sinon.spy(instance, '_displayFilenames');
+ spyOn(instance, '_displayFilenames');
instance.input.dispatchEvent(new CustomEvent('change', { bubbles: true }));
- expect(spy).to.have.been.called;
+ expect(instance._displayFilenames).toHaveBeenCalled();
});
- after(function() {
+ afterAll(function() {
instance.release();
document.body.removeChild(wrapper);
});
@@ -311,9 +327,9 @@ describe('File Uploader', function() {
div.id = 'bob';
div.innerHTML = testHTML;
document.body.appendChild(div);
- const spy = sinon.spy(instance, '_handleStateChange');
+ spyOn(instance, '_handleStateChange');
instance._handleStateChange([...document.querySelectorAll('.test')], 1, div);
- expect(spy).to.have.been.called;
+ expect(instance._handleStateChange).toHaveBeenCalled();
document.body.removeChild(div);
});
diff --git a/tests/spec/floating-menu_spec.js b/tests/spec/floating-menu_spec.js
index 49560dcda7ac..e51b3360bd6a 100644
--- a/tests/spec/floating-menu_spec.js
+++ b/tests/spec/floating-menu_spec.js
@@ -7,13 +7,13 @@ describe('Test floating menu', function() {
it('Should throw if root element is not given', function() {
expect(() => {
new FloatingMenu();
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('Should throw if root element is not a DOM element', function() {
expect(() => {
new FloatingMenu(document.createTextNode(''));
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
});
@@ -21,19 +21,19 @@ describe('Test floating menu', function() {
let menu;
it('Should use bottom by default', function() {
- expect((menu = new FloatingMenu(document.createElement('div'))).options.direction).to.equal('bottom');
+ expect((menu = new FloatingMenu(document.createElement('div'))).options.direction).toBe('bottom');
});
it('Should read the direction from data-floating-menu-direction', function() {
const element = document.createElement('div');
element.dataset.floatingMenuDirection = 'left';
- expect((menu = new FloatingMenu(element)).options.direction).to.equal('left');
+ expect((menu = new FloatingMenu(element)).options.direction).toBe('left');
});
it('Should use options.direction over data-floating-menu-direction', function() {
const element = document.createElement('div');
element.dataset.floatingMenuDirection = 'left';
- expect((menu = new FloatingMenu(element, { direction: 'right' })).options.direction).to.equal('right');
+ expect((menu = new FloatingMenu(element, { direction: 'right' })).options.direction).toBe('right');
});
afterEach(function() {
@@ -51,7 +51,7 @@ describe('Test floating menu', function() {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = HTML;
- before(function() {
+ beforeAll(function() {
element = tempDiv.querySelector('ul.bx--overflow-menu-options');
document.body.appendChild(element);
refNode = document.createElement('div');
@@ -66,79 +66,79 @@ describe('Test floating menu', function() {
it("Should sanity check show()'s arguments", function() {
expect(() => {
menu.show({});
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM Node should be given for launching element.');
});
it('Should have show() do nothing if already visible', function() {
element.classList.add('my-floating-menu-open');
- const spy = sinon.spy();
+ const spy = jasmine.createSpy();
events.on(element, 'floating-menu-beingshown', spy);
menu.show();
- expect(element.classList.contains('my-floating-menu-open'), 'Menu state').to.be.true;
- expect(refNode.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').to.be.false;
- expect(spy, 'floating-menu-beingshown event').not.have.been.called;
+ expect(element.classList.contains('my-floating-menu-open'), 'Menu state').toBe(true);
+ expect(refNode.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').toBe(false);
+ expect(spy, 'floating-menu-beingshown event').not.toHaveBeenCalled();
});
it('Should have show() method show menu', function() {
- const spy = sinon.spy();
+ const spy = jasmine.createSpy();
events.on(menu.element, 'floating-menu-shown', spy);
menu.show();
- expect(element.classList.contains('my-floating-menu-open'), 'Menu state').to.be.true;
- expect(refNode.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').to.be.true;
- expect(spy, 'floating-menu-shown event').have.been.calledOnce;
+ expect(element.classList.contains('my-floating-menu-open'), 'Menu state').toBe(true);
+ expect(refNode.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').toBe(true);
+ expect(spy, 'floating-menu-shown event').toHaveBeenCalledTimes(1);
});
it('Should call callback of show() method after it finishes', function() {
- const spy = sinon.spy();
+ const spy = jasmine.createSpy();
menu.show(spy);
menu.element.dispatchEvent(new CustomEvent('transitionend', { bubbles: true }));
- expect(spy).have.been.calledOnce;
+ expect(spy).toHaveBeenCalledTimes(1);
});
it("Should sanity check hide()'s arguments", function() {
expect(() => {
menu.hide({});
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM Node should be given for launching element.');
});
it('Should have hide() not hide if not visible already', function() {
- const spy = sinon.spy();
+ const spy = jasmine.createSpy();
events.on(element, 'floating-menu-beinghidden', spy);
menu.hide();
menu.element.dispatchEvent(new CustomEvent('transitionend', { bubbles: true }));
- expect(element.classList.contains('my-floating-menu-open'), 'Menu state').to.be.false;
- expect(element.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').to.be.false;
- expect(spy, 'floating-menu-beinghidden event').not.have.been.called;
+ expect(element.classList.contains('my-floating-menu-open'), 'Menu state').toBe(false);
+ expect(element.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').toBe(false);
+ expect(spy, 'floating-menu-beinghidden event').not.toHaveBeenCalled();
});
it('Should have hide() method hide menu', function() {
menu.show();
menu.element.dispatchEvent(new CustomEvent('transitionend', { bubbles: true }));
- const spy = sinon.spy();
+ const spy = jasmine.createSpy();
events.on(element, 'floating-menu-hidden', spy);
menu.hide();
- expect(element.classList.contains('my-floating-menu-open'), 'Menu state').to.be.false;
- expect(element.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').to.be.false;
- expect(spy, 'floating-menu-hidden event').to.be.called;
+ expect(element.classList.contains('my-floating-menu-open'), 'Menu state').toBe(false);
+ expect(element.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').toBe(false);
+ expect(spy, 'floating-menu-hidden event').toHaveBeenCalled();
});
it('Should have changeState() do nothing if the new state is neither shown or nor hidden', function() {
- const spyBeingShown = sinon.spy();
- const spyBeingHidden = sinon.spy();
+ const spyBeingShown = jasmine.createSpy();
+ const spyBeingHidden = jasmine.createSpy();
events.on(element, 'floating-menu-beingshown', spyBeingShown);
events.on(element, 'floating-menu-beinghidden', spyBeingHidden);
menu.changeState('foo');
- expect(element.classList.contains('my-floating-menu-open'), 'Menu state').to.be.false;
- expect(refNode.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').to.be.false;
- expect(spyBeingShown, 'floating-menu-beingshown event').not.have.been.called;
- expect(spyBeingHidden, 'floating-menu-beinghidden event').not.have.been.called;
+ expect(element.classList.contains('my-floating-menu-open'), 'Menu state').toBe(false);
+ expect(refNode.classList.contains('my-floating-menu-trigger-open'), 'Trigger button state').toBe(false);
+ expect(spyBeingShown, 'floating-menu-beingshown event').not.toHaveBeenCalled();
+ expect(spyBeingHidden, 'floating-menu-beinghidden event').not.toHaveBeenCalled();
});
it("Should fire event on delegator node if it's given", function() {
- const spy = sinon.spy();
+ const spy = jasmine.createSpy();
events.on(refNode, 'floating-menu-shown', spy);
menu.changeState('shown', { delegatorNode: refNode });
- expect(spy, 'floating-menu-shown event').have.been.calledOnce;
+ expect(spy, 'floating-menu-shown event').toHaveBeenCalledTimes(1);
});
afterEach(function() {
@@ -147,7 +147,7 @@ describe('Test floating menu', function() {
events.reset();
});
- after(function() {
+ afterAll(function() {
if (menu) {
menu.release();
menu = null;
@@ -174,16 +174,16 @@ describe('Test floating menu', function() {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = HTML;
- before(function() {
+ beforeAll(function() {
window.scrollY = 500;
element = tempDiv.querySelector('ul.bx--overflow-menu-options');
- sinon.stub(element, 'getBoundingClientRect', () => ({
+ spyOn(element, 'getBoundingClientRect').and.callFake(() => ({
width: 400,
height: 400,
}));
document.body.appendChild(element);
refNode = document.createElement('div');
- sinon.stub(refNode, 'getBoundingClientRect', () => ({
+ spyOn(refNode, 'getBoundingClientRect').and.callFake(() => ({
left: 100,
top: 200,
right: 300,
@@ -206,29 +206,29 @@ describe('Test floating menu', function() {
it('Should place the menu at the left', function() {
menu.options.direction = 'left';
menu.show();
- expect(element.style.left).to.equal('-325px');
- expect(element.style.top).to.equal('150px');
+ expect(element.style.left).toBe('-325px');
+ expect(element.style.top).toBe('150px');
});
it('Should place the menu at the top', function() {
menu.options.direction = 'top';
menu.show();
- expect(element.style.left).to.equal('25px');
- expect(element.style.top).to.equal('-250px');
+ expect(element.style.left).toBe('25px');
+ expect(element.style.top).toBe('-250px');
});
it('Should place the menu at the right', function() {
menu.options.direction = 'right';
menu.show();
- expect(element.style.left).to.equal('325px');
- expect(element.style.top).to.equal('150px');
+ expect(element.style.left).toBe('325px');
+ expect(element.style.top).toBe('150px');
});
it('Should place the menu at the bottom', function() {
menu.options.direction = 'bottom';
menu.show();
- expect(element.style.left).to.equal('25px');
- expect(element.style.top).to.equal('450px');
+ expect(element.style.left).toBe('25px');
+ expect(element.style.top).toBe('450px');
});
it('Should throw if refNode is not there', function() {
@@ -236,7 +236,7 @@ describe('Test floating menu', function() {
try {
expect(() => {
menu.show();
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'Cannot find the refernce node for changing the style.');
} finally {
menu.options.refNode = refNode;
}
@@ -247,7 +247,7 @@ describe('Test floating menu', function() {
element.classList.remove('my-floating-menu-trigger-open');
});
- after(function() {
+ afterAll(function() {
if (menu) {
menu.release();
menu = null;
@@ -276,7 +276,7 @@ describe('Test floating menu', function() {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = HTML;
- before(function() {
+ beforeAll(function() {
refNode = document.createElement('div');
document.body.appendChild(refNode);
});
@@ -295,13 +295,13 @@ describe('Test floating menu', function() {
it('Should move to body by default', function() {
menu.show();
- expect(element.parentNode).to.equal(document.body);
+ expect(element.parentNode).toBe(document.body);
});
it('Should move to element with data-floating-menu-container attribute', function() {
container.dataset.floatingMenuContainer = '';
menu.show();
- expect(element.parentNode).to.equal(container);
+ expect(element.parentNode).toBe(container);
});
afterEach(function() {
@@ -324,7 +324,7 @@ describe('Test floating menu', function() {
events.reset();
});
- after(function() {
+ afterAll(function() {
if (refNode) {
if (refNode.parentNode) {
refNode.parentNode.removeChild(refNode);
@@ -338,12 +338,10 @@ describe('Test floating menu', function() {
let menu;
let element;
let refNode;
- let spyPlace;
- let stubRAF;
const tempDiv = document.createElement('div');
tempDiv.innerHTML = HTML;
- before(function() {
+ beforeAll(function() {
element = tempDiv.querySelector('ul.bx--overflow-menu-options');
document.body.appendChild(element);
refNode = document.createElement('div');
@@ -353,34 +351,32 @@ describe('Test floating menu', function() {
classShown: 'my-floating-menu-open',
classRefShown: 'my-floating-menu-trigger-open',
});
- spyPlace = sinon.spy(menu, '_place');
- stubRAF = sinon.stub(window, 'requestAnimationFrame', callback => {
+ });
+
+ beforeEach(function() {
+ spyOn(menu, '_place');
+ spyOn(window, 'requestAnimationFrame').and.callFake(callback => {
callback();
});
});
it('Should handle resizing while shown', function() {
menu.show();
- spyPlace.reset();
+ menu._place.calls.reset();
window.dispatchEvent(new CustomEvent('resize'));
- expect(spyPlace).to.have.been.calledOnce;
+ expect(menu._place).toHaveBeenCalledTimes(1);
});
it('Should not handle resizing while hidden', function() {
window.dispatchEvent(new CustomEvent('resize'));
- expect(spyPlace).not.to.have.been.called;
+ expect(menu._place).not.toHaveBeenCalled();
});
afterEach(function() {
menu.hide();
- spyPlace.reset();
});
- after(function() {
- if (stubRAF) {
- stubRAF.restore();
- stubRAF = null;
- }
+ afterAll(function() {
if (menu) {
menu.release();
menu = null;
@@ -406,11 +402,10 @@ describe('Test floating menu', function() {
let primaryFocusNode;
let refNode;
let input;
- let spyFocusRefNode;
const tempDiv = document.createElement('div');
tempDiv.innerHTML = HTML;
- before(function() {
+ beforeAll(function() {
element = tempDiv.querySelector('ul.bx--overflow-menu-options');
document.body.appendChild(element);
primaryFocusNode = element.querySelector('[data-floating-menu-primary-focus]');
@@ -423,19 +418,19 @@ describe('Test floating menu', function() {
classShown: 'my-floating-menu-open',
classRefShown: 'my-floating-menu-trigger-open',
});
- spyFocusRefNode = sinon.spy(refNode, 'focus');
});
it('Should close menu when both the trigger button and the menu lose focus', function() {
primaryFocusNode.focus();
menu.changeState('shown', {});
input.focus();
- expect(element.classList.contains('bx--overflow-menu-options--open')).to.be.false;
+ expect(element.classList.contains('bx--overflow-menu-options--open')).toBe(false);
});
it('Should focus back on the trigger button when floating menu loses focus', function() {
const hasFocusin = 'onfocusin' in window;
const focusinEventName = hasFocusin ? 'focusin' : 'focus';
+ spyOn(refNode, 'focus');
primaryFocusNode.focus();
menu.changeState('shown', {});
// Firefox does not fire `onfocus` event with `input.focus()` call, presumably when the window does not have focus
@@ -444,21 +439,14 @@ describe('Test floating menu', function() {
relatedTarget: primaryFocusNode,
})
);
- expect(spyFocusRefNode).to.have.been.calledOnce;
+ expect(refNode.focus).toHaveBeenCalledTimes(1);
});
afterEach(function() {
element.classList.remove('bx--overflow-menu-options--open');
- if (spyFocusRefNode) {
- spyFocusRefNode.reset();
- }
});
- after(function() {
- if (spyFocusRefNode) {
- spyFocusRefNode.restore();
- spyFocusRefNode = null;
- }
+ afterAll(function() {
if (menu) {
menu = menu.release();
}
diff --git a/tests/spec/interior-left-nav_spec.js b/tests/spec/interior-left-nav_spec.js
index 0db3138f300d..9d7ee36ea2f9 100644
--- a/tests/spec/interior-left-nav_spec.js
+++ b/tests/spec/interior-left-nav_spec.js
@@ -7,13 +7,13 @@ describe('Test interior left nav', function() {
it('Should throw if root element is not given', function() {
expect(() => {
new InteriorLeftNav();
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('Should throw if root element is not a DOM element', function() {
expect(() => {
new InteriorLeftNav(document.createTextNode(''));
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
});
@@ -31,10 +31,9 @@ describe('Test interior left nav', function() {
});
it('should be called', function() {
- const spy = sinon.spy(instance, 'hookListItemsEvents');
+ spyOn(instance, 'hookListItemsEvents');
instance.hookListItemsEvents();
- expect(spy).to.have.been.called;
- spy.restore();
+ expect(instance.hookListItemsEvents).toHaveBeenCalled();
});
afterEach(function() {
@@ -59,7 +58,7 @@ describe('Test interior left nav', function() {
it('Should have a default setting of false', function() {
instance1 = new InteriorLeftNav(element);
- expect(instance1.options.keepOpen).to.be.false;
+ expect(instance1.options.keepOpen).toBe(false);
document.body.removeChild(container);
instance1.release();
});
@@ -68,7 +67,7 @@ describe('Test interior left nav', function() {
instance2 = new InteriorLeftNav(element, {
keepOpen: true,
});
- expect(instance2.options.keepOpen).to.be.true;
+ expect(instance2.options.keepOpen).toBe(true);
document.body.removeChild(container);
instance2.release();
});
@@ -80,7 +79,7 @@ describe('Test interior left nav', function() {
document.body.appendChild(container2);
element = document.querySelector('[data-interior-left-nav]');
instance3 = new InteriorLeftNav(element);
- expect(instance3.keepOpen).to.be.true;
+ expect(instance3.keepOpen).toBe(true);
document.body.removeChild(container2);
instance3.release();
});
@@ -100,7 +99,7 @@ describe('Test interior left nav', function() {
}
const expanded = document.querySelectorAll('.left-nav-list__item--expanded');
- expect(expanded.length).to.equal(nested.length);
+ expect(expanded.length).toBe(nested.length);
});
});
@@ -119,10 +118,9 @@ describe('Test interior left nav', function() {
it('should be called', function() {
const item = document.querySelector(instance.options.selectorLeftNavListItem);
- const spy = sinon.spy(instance, 'addActiveListItem');
+ spyOn(instance, 'addActiveListItem');
instance.addActiveListItem(item);
- expect(spy).to.have.been.called;
- spy.restore();
+ expect(instance.addActiveListItem).toHaveBeenCalled();
});
afterEach(function() {
diff --git a/tests/spec/left-nav_spec.js b/tests/spec/left-nav_spec.js
index 724efe5dbe77..dd051a3d4c59 100644
--- a/tests/spec/left-nav_spec.js
+++ b/tests/spec/left-nav_spec.js
@@ -5,13 +5,13 @@ describe('Test Left Navigation', function() {
it('Should throw if root element is not given', function() {
expect(() => {
new LeftNav();
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('Should throw if root element is not a DOM element', function() {
expect(() => {
new LeftNav(document.createTextNode(''));
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
});
diff --git a/tests/spec/lightbox_spec.js b/tests/spec/lightbox_spec.js
index fb3c11baa803..fff15ebd5987 100644
--- a/tests/spec/lightbox_spec.js
+++ b/tests/spec/lightbox_spec.js
@@ -1,6 +1,6 @@
-import 'core-js/modules/es6.weak-map'; // For PhantomJS
import Lightbox from '../../src/components/lightbox/lightbox';
import HTML from '../../src/components/lightbox/lightbox.html';
+import flattenOptions from '../utils/flatten-options';
describe('Lightbox', () => {
describe('Constructor', () => {
@@ -18,17 +18,17 @@ describe('Lightbox', () => {
it('Should throw if root element is not given', () => {
expect(() => {
new Lightbox();
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('Should throw if root element is not a DOM element', () => {
expect(() => {
new Lightbox(document.createTextNode(''));
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('should set default options', () => {
- expect(instance.options).to.deep.equal({
+ expect(flattenOptions(instance.options)).toEqual({
selectorInit: '[data-lightbox]',
selectorScrollRight: '[data-scroll-right]',
selectorScrollLeft: '[data-scroll-left]',
@@ -56,12 +56,11 @@ describe('Lightbox', () => {
});
it('should be called on click', () => {
- const spy = sinon.spy(instance, 'updateSlide');
+ spyOn(instance, 'updateSlide');
const event = new CustomEvent('click', { bubbles: true });
const rightButton = element.querySelector(instance.options.selectorScrollRight);
rightButton.dispatchEvent(event);
- expect(spy).to.have.been.called;
- spy.restore();
+ expect(instance.updateSlide).toHaveBeenCalled();
});
afterEach(() => {
diff --git a/tests/spec/loading_spec.js b/tests/spec/loading_spec.js
index 3f5b452f8616..691215a21862 100644
--- a/tests/spec/loading_spec.js
+++ b/tests/spec/loading_spec.js
@@ -6,54 +6,54 @@ describe('Test Loading', function() {
it('Should throw if root element is not given', function() {
expect(() => {
new Loading();
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('Should throw if root element is not a DOM element', function() {
expect(() => {
new Loading(document.createTextNode(''));
- }).to.throw(Error);
+ }).toThrowError(TypeError, 'DOM element should be given to initialize this widget.');
});
it('Should set default state to active', function() {
const spinner = new Loading(document.createElement('div'));
- expect(spinner.isActive()).to.equal(true);
+ expect(spinner.isActive()).toBe(true);
});
it('Should accept options', function() {
const options = { active: false };
const spinner = new Loading(document.createElement('div'), options);
- expect(spinner.isActive()).to.equal(false);
+ expect(spinner.isActive()).toBe(false);
});
});
describe('set()', function() {
it('Should throw if boolean is not passed in', function() {
const spinner = new Loading(document.createElement('div'));
- expect(() => spinner.set()).to.throw(Error);
- expect(() => spinner.set('true')).to.throw(Error);
+ expect(() => spinner.set()).toThrowError(TypeError, 'set expects a boolean.');
+ expect(() => spinner.set('true')).toThrowError(TypeError, 'set expects a boolean.');
});
it('Should set state', function() {
const spinner = new Loading(document.createElement('div'));
spinner.set(true);
- expect(spinner.isActive()).to.be.true;
+ expect(spinner.isActive()).toBe(true);
spinner.set(false);
- expect(spinner.isActive()).to.be.false;
+ expect(spinner.isActive()).toBe(false);
});
it('Should return self', function() {
const spinner = new Loading(document.createElement('div'));
- expect(spinner.set(true)).to.equal(spinner);
+ expect(spinner.set(true)).toBe(spinner);
});
it('Should remove and add bx--loading--stop class attribute of DOM element', function() {
const spinner = new Loading(document.createElement('div'));
spinner.set(false);
- expect(spinner.element.classList.contains('bx--loading--stop'), 'Class for stopped state').to.be.true;
+ expect(spinner.element.classList.contains('bx--loading--stop'), 'Class for stopped state').toBe(true);
spinner.set(true);
- expect(spinner.element.classList.contains('bx--loading--stop'), 'Class for started state').to.be.false;
+ expect(spinner.element.classList.contains('bx--loading--stop'), 'Class for started state').toBe(false);
});
});
@@ -61,16 +61,16 @@ describe('Test Loading', function() {
it('Should toggle', function() {
const spinner = new Loading(document.createElement('div'));
spinner.toggle();
- expect(spinner.isActive()).to.equal(false);
+ expect(spinner.isActive()).toBe(false);
spinner.toggle();
- expect(spinner.isActive()).to.equal(true);
+ expect(spinner.isActive()).toBe(true);
});
});
describe('isActive()', function() {
it('Should return spinner state', function() {
const spinner = new Loading(document.createElement('div'));
- expect(spinner.isActive()).to.equal(true);
+ expect(spinner.isActive()).toBe(true);
});
});
@@ -88,15 +88,15 @@ describe('Test Loading', function() {
});
it('Should be called', function() {
- const spy = sinon.spy(instance, '_deleteElement');
+ spyOn(instance, '_deleteElement');
instance._deleteElement();
- expect(spy).to.have.been.called;
+ expect(instance._deleteElement).toHaveBeenCalled();
});
it('Should remove loading element from the DOM', function() {
instance._deleteElement();
const loadingEl = document.querySelector('[data-loading]');
- expect(loadingEl).to.be.a('null');
+ expect(loadingEl).toBe(null);
});
afterEach(function() {
@@ -119,14 +119,14 @@ describe('Test Loading', function() {
});
it('Should be called', function() {
- const spy = sinon.spy(instance, 'end');
+ spyOn(instance, 'end');
instance.end();
- expect(spy).to.have.been.called;
+ expect(instance.end).toHaveBeenCalled();
});
it('Should set state to inactive', function() {
instance.end();
- expect(instance.isActive()).to.equal(false);
+ expect(instance.isActive()).toBe(false);
});
afterEach(function() {
@@ -138,7 +138,7 @@ describe('Test Loading', function() {
describe('Managing instances', function() {
let element;
- before(function() {
+ beforeAll(function() {
element = document.createElement('a');
});
@@ -148,7 +148,7 @@ describe('Test Loading', function() {
try {
first = Loading.create(element);
second = Loading.create(element);
- expect(first).to.equal(second);
+ expect(first).toBe(second);
} finally {
first && first.release();
if (first !== second) {
@@ -164,7 +164,7 @@ describe('Test Loading', function() {
first = Loading.create(element);
first.release();
second = Loading.create(element);
- expect(first).not.to.equal(second);
+ expect(first).not.toBe(second);
} finally {
first && first.release();
if (first !== second) {
diff --git a/tests/spec/misc/svg-toggle-class_spec.js b/tests/spec/misc/svg-toggle-class_spec.js
index 00c04ba92fbc..518d7b0be732 100644
--- a/tests/spec/misc/svg-toggle-class_spec.js
+++ b/tests/spec/misc/svg-toggle-class_spec.js
@@ -6,36 +6,36 @@ describe('Test toggling class for