Ошибка типа: невозможно прочитать свойства неопределенного (чтение «css») теста JestJsJquery

Программирование на jquery
Anonymous
Ошибка типа: невозможно прочитать свойства неопределенного (чтение «css») теста JestJs

Сообщение Anonymous »

Я получаю эту ошибку при попытке запустить тест моего кода JQuery

Код: Выделить всё

TypeError: Cannot read properties of undefined (reading 'css')

20 |
21 | export const alertError = (message, errorclass) => {
> 22 |   $(`.${errorclass}`).css("display", "block");
|                      ^
23 |   $(`.${errorclass}`).html(`
24 |     
25 |       

at alertError (static/js/utils/alert.js:22:22)
at getUserChatrooms (static/js/modules/chat/chat_ajax.js:29:19)
at Object. (static/js/modules/chat/tests/chat_ajax.spec.js:38:45)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 5 passed, 6 total
Мои текущие макеты/jquery.js

Код: Выделить всё

import $ from 'jquery';

// Mock jQuery and attach it to the global object
global.$ = $;
global.jQuery = $;

// Turn off jQuery animations
jQuery.fx.off = true;

// Mock specific jQuery instances
$.fn.extend = jest.fn();
$.ajax = jest.fn();
$.fn = {
on: jest.fn().mockReturnThis(),
children: jest.fn().mockReturnThis(),
attr: jest.fn().mockReturnThis(),
css: jest.fn().mockReturnThis(),
html: jest.fn().mockReturnThis(),
};

$.document = $();
$.document.body = $();
Как это исправить? Я не могу придумать, как это исправить, не имитируя функции alert.js.

Подробнее здесь: https://stackoverflow.com/questions/786 ... estjs-test

Вернуться в «Jquery»