TypeError: Cannot read properties of undefined (reading 'testTimeout') - jestjs

The jest 0.29 test case is to test component snapshot. Here is the error:
FAIL src/components/post/piece/Itemdetail.test.js
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'testTimeout')
at _callCircusHook (node_modules/jest-circus/build/run.js:237:57)
The error is complaining about a jest -circus module. This is confusing as the error is about a jest module. here is the line of code being complained:
const timeout = hook.timeout || (0, _state.getState)().testTimeout; //<<==run.js:237:57. _state is an import module.
How do I mock testTimeout for the jest-circus module to calm the error?

Here is the line of code causing the error:
global = {_smartContractObj:{wallet:"0x4k5jk43k6j5k4j5"}};
The error disappeared after the change (don't know why):
global._smartContractObj = {wallet:"0x4k5jk43k6j5k4j5"};

Related

TypeError: TextEncoder is not a constructor

I was trying to run tests using supertest in nodejs and I got this error message
ReferenceError: TextEncoder is not defined
Then i was advised to locate the file "node_modules/whatwg-url/lib/encoding.js" and add this lines of code at the top
const { TextEncoder, TextDecoder } = require("./utils");
After i did that, i started getting this message
TypeError: TextEncoder is not a constructor
please, i am using node version 17.4.0

Before test runs, fails on CCI pipeline: "TypeError: Cannot read property 'createEvent' of null"

I have tried researching other topics similar to this error message ( such as from here, here, here among others. ):
TypeError: Cannot read property 'createEvent' of null
In our test suit we have a lot of mocked network calls as a single mocking layer, but there is a throw new Error('unexpected URL') handler for missing calls.
Also, I have verified all of my ReactTesting findBy queries are correctly declared with async/await syntax. Sometimes the tests work, othertimes fails.
What is really curious, is the error happens ONLY in Circle CI before any tests run, it appears, based on the error message call stack:
#!/bin/bash -eo pipefail
yarn test:ci
yarn run v1.22.11
$ jest --ci --runInBand
/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905
var evt = document.createEvent('Event');
^
TypeError: Cannot read property 'createEvent' of null
at Object.invokeGuardedCallbackDev (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905:26)
at invokeGuardedCallback (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
at flushPassiveEffectsImpl (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23543:11)
at unstable_runWithPriority (/home/circleci/project/node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js:468:12)
at runWithPriority$1 (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
at flushPassiveEffects (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
at Object.<anonymous>.flushWork (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
at Immediate.<anonymous> (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1003:11)
at processImmediate (internal/timers.js:464:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
I have not seen this error locally, even when running the same command as my Circle CI command.
Any ideas about this, other than unhandled
Can you try this. async() await and use expect() function and also catch the execption by new Error Object.
it("Should ...", async () => {
await myFn(async () => {
// some operations
expect(await element.length).toBe(10).toThrow(new Error("something went wrong!"))
});
});
Try adding expect(something...) to the tests, like mentioned here.
You should finish your test with some sort of an assertion.

Shopify React Next Cannot read property "/_app" of undefined

I am trying to setup an environment to develop a shopify theme, and I followed the tutorial found here:
https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/build-your-user-interface-with-polaris
But when I connected my server, the app, the store and so on, when I started integrating polaris, on build I started getting errors.
First I had an error about a missing module build-manifest.json and I found a suggestion somewhere on the forums to make a blank file with just {} in it in the .next/ directory and so I did.
Then it complained about react-loadable-manifest.json missing, and I did the same for it.
Both of these errors were being thrown from this piece of code:
server.use(async (ctx) => {
await handle(ctx.req, ctx.res); // <-- this line
ctx.respond = false;
ctx.res.statusCode = 200;
return;
});
And now I have the following errors:
error - ./node_modules/#shopify/polaris/dist/styles.css
TypeError: Cannot read property 'tapAsync' of undefined
TypeError: Cannot read property '/_app' of undefined
Thats the full stack, I dont see any "custom" code related to it:
error - ./node_modules/#shopify/polaris/dist/styles.css
TypeError: Cannot read property 'tapAsync' of undefined
TypeError: Cannot read property '/_app' of undefined
at getPageFiles (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\get-page-files.js:1:311)
at getDocumentFiles (C:\Users\Darkbound\Desktop\shopifyreact\server\.next\server\pages\_document.js:266:54)
at Head.render (C:\Users\Darkbound\Desktop\shopifyreact\server\.next\server\pages\_document.js:589:19)
at processChild (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3450:18)
at resolve (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3270:5)
at ReactDOMServerRenderer.render (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3753:22)
at ReactDOMServerRenderer.read (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3690:29)
at renderToStaticMarkup (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:4314:27)
at renderDocument (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\render.js:3:715)
at renderToHTML (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\render.js:56:103)
at async C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:107:97
at async C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:100:142
at async DevServer.renderToHTMLWithComponents (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:132:387)
at async DevServer.renderErrorToHTML (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:134:327)
at async DevServer.render (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:72:236)
at async Object.fn (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:56:580)
I came across this issue when jumping next multiple dependencies versions at once. I was able to resolve it by removing the wrapped Container
https://github.com/vercel/next.js/blob/master/errors/app-container-deprecated.md

Openlayers 6 TypeError: URL.createObjectURL is not a function

I have a question, after i update the openlayers from 5.3.1 to 6.3.1, when i run test, jest or mocha, both show the error "TypeError: URL.createObjectURL is not a function", what is the reason?
Mocha-Webpack:
TypeError: URL.createObjectURL is not a function
at eval (webpack:///./node_modules/ol/worker/webgl.js?:7:15)
Jest:
FAIL test/map.test.js
● Test suite failed to run
TypeError: URL.createObjectURL is not a function
> 1 | import {Vector as VectorLayer} from "ol/layer.js";
| ^

Multiple strange errors when trying to import React component from local npm package

I have a npm package of React components and an example Meteor.js app which will be used to display their usage. To install my local npm package I ran npm install --save ../library and it successfully added the dependency as "library": "file:///path/to/lib".
However, when I import one of the components and try to use them, the console spams 29 errors, starting with:
Uncaught SyntaxError:
Unexpected token import
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'Random' of undefined
Uncaught TypeError:
Cannot read property 'meteorInstall' of undefined
Uncaught TypeError:
Cannot read property 'MongoID' of undefined
The code:
import React, { PropTypes } from 'react';
import Button from 'library/components/button/Button.jsx'
export default class App extends React.Component {
render() {
return (
<div>
<Button>Click Me</Button>
</div>
);
}
}
Removing the <Button/> component and it's import removes the error. What is going on here?
EDIT: Digging deeper, if I click on the Unexpected token import error, it shows me the line where I import React in my libraries Button component. Could the issue be related to it somehow not understanding ES6 imports properly?

Resources