Шутка: консоль показывает переменную, ошибка броска узла - PullRequest
0 голосов
/ 17 мая 2019

В приведенном ниже выводе Jest вы можете увидеть противоречивую информацию о назначении модуля:

    ReferenceError: ajaxUrl is not def FAIL  views/admin/__tests__/CurrentCouponListingSection.test.js
  ✕ getCountOfCurrentTargets (8ms)
  ✓ adjustResultMarker (5ms)

  ● getCountOfCurrentTargets

    ReferenceError: ajaxUrl is not defined

       9 |   
      10 |   jQuery.ajax(
    > 11 |     ajaxUrl,
         |     ^
      12 |     {
      13 |       method: 'POST',
      14 |       async: false, 

      at Object.ajaxUrl [as getCountOfCurrentTargets] (views/admin/CurrentCouponListingSection.js:11:5)
      at Object.getCountOfCurrentTargets (views/admin/__tests__/CurrentCouponListingSection.test.js:5:19)

  console.log views/admin/CurrentCouponListingSection.js:4
    http://test.com =====ajaxUrl=====

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        0.448s, estimated 1s
Ran all test suites related to changed files.

Вот код, который вызывает Джест. Любые идеи, почему узел видит module как неопределенный?

const testFile = require("../CurrentCouponListingSection.js");

test('getCountOfCurrentTargets', () => {
  expect(testFile.getCountOfCurrentTargets($))
    .toEqual(14);
});

.

if (typeof 'module' !== undefined) {
  const ajaxUrl = 'http://test.com';
  console.log(ajaxUrl, `=====ajaxUrl=====`); // http://test.com
}    

const getCountOfCurrentTargets = (jQuery) => {
  let countOfCurrentTargets = null;

  jQuery.ajax(
    ajaxUrl,
    {
      method: 'POST',
      async: false,
      dataType: 'json',
      data: {
        action: 'getCountOfCurrentTargets',
      },
      success: response => {
        countOfCurrentTargets = response;
      },
      error: error => console.log(error, `=====error=====`),
    }
  );

  return countOfCurrentTargets;
};
if (typeof 'module' !== undefined) {
  module.exports.getCountOfCurrentTargets = getCountOfCurrentTargets;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...