2021年4月30日星期五

Why is Jest still not mocking out my function properly?

I'm trying to use Jest as my app's testing suite. Currently in the process of mocking an Electron function so that my test can actually run. I'm using Electron v.8.2.2. Here's the error I'm getting:

FAIL  __tests__/Home.test.js    ● Test suite failed to run        TypeError: window.require is not a function           9 | import './Monaco.scss';        10 |      > 11 | const { remote } = window.require('electron');           |                           ^        12 | const electronFs = remote.require('fs');        13 |        14 | const Monaco = () => {          at Object.<anonymous> (src/components/Monaco/Monaco.tsx:11:27)        at Object.<anonymous> (src/components/Home/Home.tsx:9:1)        at Object.<anonymous> (__tests__/Home.test.js:1:1)  

Based on this error, I'm interpreting that remote is supposed to be a function. Here is the mock file and function that I wrote for remote.

//__mocks__/remote.js    import { remote } from "electron";    remote = jest.fn();  export default remote;  

I'm still getting the above error even with this mock function I wrote. Any thoughts as to what's going wrong?

https://stackoverflow.com/questions/67342230/why-is-jest-still-not-mocking-out-my-function-properly May 01, 2021 at 09:48AM

没有评论:

发表评论