Skip to content

Commit

Permalink
test: 💍 (upgrade) upgrade test to the latest jest version
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Mar 2, 2022
1 parent 002e020 commit d3ed313
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {NgsgClassService} from './ngsg-class.service';
import createSpy = jasmine.createSpy;

describe('NgsgClassService', () => {

Expand All @@ -8,56 +7,56 @@ describe('NgsgClassService', () => {
beforeEach(() => sut = new NgsgClassService());

it('should add the placeholder class', () => {
const addClassSpy = createSpy();
const addClassSpy = jest.fn();
const element = {classList: {add: addClassSpy}} as any;
sut.addPlaceHolderClass(element);
expect(addClassSpy).toHaveBeenCalledWith('ng-sg-placeholder');
});

it('should remove the placeholder class', () => {
const removeClassSpy = createSpy();
const removeClassSpy = jest.fn();
const element = {classList: {remove: removeClassSpy}} as any;
sut.removePlaceHolderClass(element);
expect(removeClassSpy).toHaveBeenCalledWith('ng-sg-placeholder');
});

it('should add the dropped class', () => {
const addClassSpy = createSpy();
const addClassSpy = jest.fn();
const element = {classList: {add: addClassSpy}} as any;
sut.addDroppedClass(element);
expect(addClassSpy).toHaveBeenCalledWith('ng-sg-dropped');
});

it('should remove the placeholder class', () => {
const removeClassSpy = createSpy();
const removeClassSpy = jest.fn();
const element = {classList: {remove: removeClassSpy}} as any;
sut.removeDroppedClass(element);
expect(removeClassSpy).toHaveBeenCalledWith('ng-sg-dropped');
});

it('should add the dropped class', () => {
const addClassSpy = createSpy();
const addClassSpy = jest.fn();
const element = {classList: {add: addClassSpy}} as any;
sut.addSelectedClass(element);
expect(addClassSpy).toHaveBeenCalledWith('ng-sg-selected');
});

it('should remove the placeholder class', () => {
const removeClassSpy = createSpy();
const removeClassSpy = jest.fn();
const element = {classList: {remove: removeClassSpy}} as any;
sut.removeSelectedClass(element);
expect(removeClassSpy).toHaveBeenCalledWith('ng-sg-selected');
});

it('should add the active class', () => {
const addClassSpy = createSpy();
const addClassSpy = jest.fn();
const element = {classList: {add: addClassSpy}} as any;
sut.addActiveClass(element);
expect(addClassSpy).toHaveBeenCalledWith('ng-sg-active');
});

it('should remove the active class', () => {
const removeClassSpy = createSpy();
const removeClassSpy = jest.fn();
const element = {classList: {remove: removeClassSpy}} as any;
sut.removeActiveClass(element);
expect(removeClassSpy).toHaveBeenCalledWith('ng-sg-active');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Scroll helper', () => {

beforeEach(() => {
sut = new ScrollHelperService(documentMock);
scrollSpy = spyOn(documentMock.defaultView, 'scrollBy');
scrollSpy = jest.spyOn(documentMock.defaultView, 'scrollBy');
});

describe('Top scroll', () => {
Expand Down
2 changes: 1 addition & 1 deletion projects/ng-sortgrid/src/lib/ngsg-item.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('NgsgItemDirective', () => {
it('should log a warning message if you drop and you did not provide any items', () => {
const expectedWarniningMessage = `Ng-sortgrid: No items provided - please use [sortGridItems] to pass in an array of items -
otherwhise the ordered items can not be emitted in the (sorted) event`;
const consoleWarnSpy = spyOn(console, 'warn');
const consoleWarnSpy = jest.spyOn(console, 'warn');
ngsgStore.hasItems = () => false;

sut.drop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('NgsgSortService', () => {

ngsgStore.getFirstSelectItem = () => ({ originalIndex: 0 } as any);
ngsgStore.getSelectedItems = () => [dragElement] as any;
const insertBeforeSpy = spyOn(dropElement.parentNode, 'insertBefore');
const insertBeforeSpy = jest.spyOn(dropElement.parentNode, 'insertBefore');
NgsgElementsHelper.findIndex = () => 1;

sut.initSort(group);
Expand All @@ -61,7 +61,7 @@ describe('NgsgSortService', () => {

ngsgStore.getFirstSelectItem = () => ({ originalIndex: 2 } as any);
ngsgStore.getSelectedItems = () => [dragElement];
const insertBeforeSpy = spyOn(dropElement.parentNode, 'insertBefore');
const insertBeforeSpy = jest.spyOn(dropElement.parentNode, 'insertBefore');
NgsgElementsHelper.findIndex = () => 1;

sut.initSort(group);
Expand Down

0 comments on commit d3ed313

Please sign in to comment.