[英]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.