TypeError: (0 , _reactTestRenderer.act) is not a function - jestjs

I am getting this error while using renderHook in my test case. Not sure what is the issue.
TypeError: (0 , _reactTestRenderer.act) is not a function
13 |
14 | it('allows to upload photos through the mutation', async () => {
> 15 | const { result, nextUpdate } = renderHook(() =>
| ^
16 | usePhotosUpload({
17 | photosUploadMutation,
18 | }),
at renderHook (../../../node_modules/react-hooks-testing-library/lib/index.js:151:30)
at Object._callee$ (__test__/hooks/usePhotosUpload.test.js:15:36)
at tryCatch (../../../node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (../../../node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (../../../node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (__test__/hooks/usePhotosUpload.test.js:13:103)
at _next (__test__/hooks/usePhotosUpload.test.js:15:194)
at __test__/hooks/usePhotosUpload.test.js:15:364
at Object.<anonymous> (__test__/hooks/usePhotosUpload.test.js:15:97)

For resolving this issue please make version same of react-test-renderer as of react in your package.json file.

Related

How to resolve Mongod instance closed with code null

I am working on an application running on Ubuntu 20.04.4 and Node.js v14.19.3. It connects to MongoDB v3.6 on Docker.
While executing a jest test, it fails with the following error log:
FAIL src/user/user.service.spec.ts (8.555 s)
● Console
console.warn
Starting the instance failed, please enable debug for more infomation
at ../../../node_modules/mongodb-memory-server-core/src/MongoMemoryServer.ts:111:19
console.log
error closing connection to mongo: "Mongod instance closed with code \"null\""
at Object.<anonymous>.exports.closeInMongodConnection (utils/test-database.ts:24:15)
● UserService › should be defined
Failed: "Mongod instance closed with code \"null\""
15 | let connection: Connection
16 |
> 17 | beforeEach(async () => {
| ^
18 | const module: TestingModule = await Test.createTestingModule({
19 | imports: [
20 | rootMongooseTestModule(),
at Env.beforeEach (../../../node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:46:24)
at Suite.<anonymous> (user/user.service.spec.ts:17:3)
at Object.<anonymous> (user/user.service.spec.ts:13:1)
● UserService › should be defined
expect(received).toBeDefined()
Received: undefined
29 |
30 | it('should be defined', () => {
> 31 | expect(service).toBeDefined()
| ^
32 | })
33 |
34 | afterAll(async () => {
at Object.<anonymous> (user/user.service.spec.ts:31:21)
Any clue on 'Mongod instance closed with code "null"' is highly appreciated.

TypeError: Cannot read property 'name' of undefined [tensorflowjs]

I get an error in tf.model when convert model from tensorflow2 to tensorflow js
That line get error:
model = tf.model({inputs: img, outputs: [a, b]})
My error:
/home/whoisltd/works/mtcnn-tfjs/node_modules/#tensorflow/tfjs-layers/dist/tf-layers.node.js:30023
finally { if (e_3) throw e_3.error; }
^
TypeError: Cannot read property 'name' of undefined
at LayersModel.Container [as constructor] (/home/whoisltd/works/mtcnn-tfjs/node_modules/#tensorflow/tfjs-layers/dist/tf-layers.node.js:30015:46)
at new LayersModel (/home/whoisltd/works/mtcnn-tfjs/node_modules/#tensorflow/tfjs-layers/dist/tf-layers.node.js:32802:28)
at Object.model (/home/whoisltd/works/mtcnn-tfjs/node_modules/#tensorflow/tfjs-layers/dist/tf-layers.node.js:35296:12)
at PNet (/home/whoisltd/works/mtcnn-tfjs/models.js:39:16)
at new MTCNN (/home/whoisltd/works/mtcnn-tfjs/mtcnn.js:16:21)
at image_demo (/home/whoisltd/works/mtcnn-tfjs/demo.js:11:13)
at Object.<anonymous> (/home/whoisltd/works/mtcnn-tfjs/demo.js:38:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
Do you know how to fix this?

Jest - I have a nested error when more than one file

I have two test files, when I rename and comment one of them, the test will pass successfuly, otherwise will always throw this error:
FAIL src/features/user/auth/register.resolver.test.ts (10.045 s)
● Register › a new user with a valid form › call register resolver and return the registered user
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "call register resolver and return the registered user".
28 | `
29 |
> 30 | describe('Login', () => {
| ^
31 | let dbConnection: Connection;
32 | let userRepository: UserRepository;
33 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/login.resolver.test.ts:30:1)
● Register › a new user with a valid form › the new user is persisted in database
expect(received).toMatchObject(expected)
Matcher error: received value must be a non-null object
Received has value: undefined
81 | });
82 |
> 83 | expect(user).toMatchObject({
| ^
84 | id: expect.any(String),
85 | username: registerInput.username,
86 | email: registerInput.email,
at Object.<anonymous> (src/features/user/auth/register.resolver.test.ts:83:20)
● Register › a new user with an invalid form › returns the errors
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "returns the errors".
28 | `
29 |
> 30 | describe('Login', () => {
| ^
31 | let dbConnection: Connection;
32 | let userRepository: UserRepository;
33 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/login.resolver.test.ts:30:1)
FAIL src/features/user/auth/login.resolver.test.ts (10.298 s)
● Login › with a valid form › call login resolver and return the logged in user
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "call login resolver and return the logged in user".
27 | `
28 |
> 29 | describe("Register", () => {
| ^
30 | let dbConnection: Connection;
31 | let userRepository: UserRepository;
32 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/register.resolver.test.ts:29:1)
● Login › with an invalid form › returns an error [login]
Tests cannot be nested. Test "encountered a declaration exception" cannot run because it is nested within "returns an error [login]".
27 | `
28 |
> 29 | describe("Register", () => {
| ^
30 | let dbConnection: Connection;
31 | let userRepository: UserRepository;
32 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:566:17)
at Object.<anonymous> (src/features/user/auth/register.resolver.test.ts:29:1)
Test Suites: 2 failed, 2 total
Tests: 5 failed, 1 passed, 6 total
Snapshots: 0 total
Time: 11.143 s
Ran all test suites.
And here the test files: https://gist.github.com/srgrcp/01fbbd4df391a90c25c8c60622bc2514
If I'm not wrong, the error says: "the is nested within ", but these tests are in different files.

Typescript Type Annotations throws 'Unexpected token ":"'

I am trying to annotate my variables with types but when running the code it simply gives off an error:
let foo: number = 23;
console.log( foo );
// let foo: number = 23;
^
// SyntaxError: Unexpected token ':'
// [90m at Object.compileFunction (node:vm:352:18)[39m
// [90m at wrapSafe (node:internal/modules/cjs/loader:1031:15)[39m
// [90m at Module._compile (node:internal/modules/cjs/loader:1065:27)[39m
// [90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)[39m
// [90m at Module.load (node:internal/modules/cjs/loader:981:32)[39m
// [90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)[39m
// [90m at Function.executeUserEntryPoint [as runMain] // (node:internal/modules/run_main:79:12)[39m
// [90m at node:internal/main/run_main_module:17:47[39m
You have two options:
First compile it to plain JS with tsc myfile.ts and run the JS file with node myfile.js.
Or npm install ts-node which lets you run TS files like you would run JS files: ts-node myfile.ts

How to use express react views lib with ES6 React code

I tried to use express-react-views as an express view engine, but it only compile React code in JSX without ES6. How can i switch to ES6 please.
This is the code im using for Error page:
import React, { Component } from "react";
class Error extends Component {
render() {
return <p>{this.props.error}</p>;
}
}
export default Error;
This is the error im having:
SyntaxError: /Users/mac/Documents/ReactJS-dev/test/views/error.jsx: Unexpected token (4:8)
[0m [90m 2 | [39m
[90m 3 | [39m[36mclass[39m [33mError[39m [36mextends[39m [33mComponent[39m {
[31m[1m>[22m[39m[90m 4 | [39m state [33m=[39m {}[33m;[39m
[90m | [39m [31m[1m^[22m[39m
[90m 5 | [39m render() {
[90m 6 | [39m [36mreturn[39m [33m<[39m[33mp[39m[33m>[39m{[36mthis[39m[33m.[39mprops[33m.[39merror}[33m<[39m[33m/[39m[33mp[39m[33m>[39m[33m;[39m
[90m 7 | [39m }[0m
at Parser.pp$5.raise (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:4454:13)
at Parser.pp.unexpected (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:1761:8)
at Parser.pp$1.parseClassProperty (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2571:50)
at Parser.parseClassProperty (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:6157:20)
at Parser.pp$1.parseClassBody (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2516:34)
at Parser.pp$1.parseClass (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2406:8)
at Parser.pp$1.parseStatement (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:1843:19)
at Parser.parseStatement (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:5910:22)
at Parser.pp$1.parseBlockBody (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2268:21)
at Parser.pp$1.parseTopLevel (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:1778:8)

Resources