简体   繁体   English

玩笑测试:TypeError: (0 , _rtb.disableAllAds) is not a function

[英]Jest testing: TypeError: (0 , _rtb.disableAllAds) is not a function

A few questions on StackOverflow are like this one, but the suggestions haven't fixed my particular problem. StackOverflow 上的一些问题与此类似,但这些建议并没有解决我的特定问题。 I don't use react, only pure JS and I'm not able to continue my testing bc of this.我不使用反应,只使用纯 JS,我无法继续我的测试 bc。 Any help is appreciated.任何帮助表示赞赏。 I'm also still new to Jest testing.我也是 Jest 测试的新手。 This is the actual error I get (I get it on the first function so the 2nd will prob throw the error too) What I don't get is it says it's not a function but it clearly is:这是我得到的实际错误(我在第一个函数上得到它,所以第二个函数也会抛出错误)我没有得到的是它说它不是一个函数,但它显然是:

● Test suite failed to run

    TypeError: (0 , _rtb.disableAllAds) is not a function

       99 |
      100 | // check for noads and dhb to disable RTB and ads
    > 101 | export const disableAds = disableAllAds(qsc);
          |                           ^
      102 | export const disableHb = disableAllHb(qsc);

A look into my files: In my index file:查看我的文件:在我的索引文件中:

import {
  disableAllAds,
  disableAllHb,
} from "../src/rtb";

export const disableAds = disableAllAds(qsc);
export const disableHb = disableAllHb(qsc);

Then in rtb.js:然后在 rtb.js 中:

import {
  disableHb,
} from '../index';

export const disableAllAds = (qsc) => (qsc.noads === true || (typeof window !== 'undefined' && window.noads === 'true')) ? true : false;
export const disableAllHb = (qsc) => (qsc.dhb === true || (typeof window !== 'undefined' && window.disableHB === 'true')) ? true : false;

And my test file - tests/rtb.test.js:还有我的测试文件——tests/rtb.test.js:

import {
  disableAllAds, 
  disableAllHb, 
} from '../src/rtb';

I get this error even before I touch the test file if I have my Jest --watch on.如果我打开了 Jest --watch,即使在我触摸测试文件之前,我也会收到此错误。 I'm not sure why this is but I need help figuring this out so I can continue writing my tests.我不确定这是为什么,但我需要帮助解决这个问题,以便我可以继续编写我的测试。

Thanks a lot for the help!非常感谢您的帮助!

I can not make sure but that seems like 'circular dependency' issue to me.我无法确定,但这对我来说似乎是“循环依赖”问题。

Are you importing rtb from index and index from rtb?您是从 index 导入 rtb,从 rtb 导入 index 吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 TypeError 不是函数(用 Jest 测试 promise) - How to fix TypeError is not a function (testing promises with Jest) 开玩笑-测试mobx存储@action TypeError:不是函数 - jest - testing mobx store @action TypeError: is not a function 如何解决错误 TypeError: x is not a function for testing the following function in Jest? - How to resolve the error TypeError: x is not a function for testing of the following function in Jest? 'TypeError: store.dispatch is not a function' redux action testing with jest - 'TypeError: store.dispatch is not a function' redux action testing with jest Angular 6 和 Jest 的测试出错 - TypeError: testing.TestBed.inject is not a function - Error in tests with Angular 6 and Jest - TypeError: testing.TestBed.inject is not a function React/Jest:测试 React Context 方法(结果:TypeError:setScore 不是函数) - React/Jest: Testing React Context methods (Result: TypeError: setScore is not a function) 开玩笑的TypeError:函数未找到 - Jest TypeError: function not found Jest TypeError:fetch 不是函数 - Jest TypeError: fetch is not a function 在 Jest 中测试嵌套的 function - Testing nested function in Jest React Jest - TypeError: (0, _[....]) 不是 function - React Jest - TypeError: (0 , _[....]) is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM