test: fixe util tests

This commit is contained in:
Barış Soner Uşaklı
2022-02-17 12:27:18 -05:00
parent 3c129d7e8f
commit 1a0b82f434
2 changed files with 5 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ const nconf = require('nconf');
const fs = require('fs');
const winston = require('winston');
const utils = require('../../public/src/utils');
const utils = require('../../src/utils');
const helpers = module.exports;

View File

@@ -3,7 +3,6 @@
const assert = require('assert');
const { JSDOM } = require('jsdom');
const utils = require('../public/src/utils');
const slugify = require('../src/slugify');
const db = require('./mocks/databasemock');
@@ -11,14 +10,16 @@ describe('Utility Methods', () => {
// https://gist.github.com/robballou/9ee108758dc5e0e2d028
// create some jsdom magic to allow jQuery to work
const dom = new JSDOM('<html><body></body></html>');
const { window } = dom;
global.window = window;
global.window = dom.window;
global.document = dom.window.document;
global.jQuery = require('jquery');
global.$ = global.jQuery;
const { $ } = global;
require('jquery-deserialize');
require('jquery-serializeobject');
const utils = require('../public/src/utils');
it('should serialize/deserialize form data properly', () => {
const formSerialize = $(`
<form id="form-serialize">
@@ -283,20 +284,10 @@ describe('Utility Methods', () => {
});
it('should return false if not touch device', (done) => {
global.document = global.document || {};
global.document.documentElement = {};
assert(!utils.isTouchDevice());
done();
});
it('should return true if touch device', (done) => {
global.document.documentElement = {
ontouchstart: 1,
};
assert(utils.isTouchDevice());
done();
});
it('should check if element is in viewport', (done) => {
const el = $('<div>some text</div>');
assert(utils.isElementInViewport(el));
@@ -304,7 +295,6 @@ describe('Utility Methods', () => {
});
it('should get empty object for url params', (done) => {
global.document = window.document;
const params = utils.params();
assert.equal(Object.keys(params), 0);
done();