Cant find setup() on userEvent - react-testing-library

I am trying to use the user-event utility in testing library as described here :
https://testing-library.com/docs/user-event/intro
Unfortunatley when I try and call the setup function
userEvent.setup()
My IDE says that it cannot be found :
Why is this happening?
My import in my file looks like this :
import userEvent from '#testing-library/user-event'
And my package dependencies look like this :
"#testing-library/dom": "^8.11.3",
"#testing-library/jest-dom": "5.7.0",
"#testing-library/react": "^12.1.2",
"#testing-library/react-hooks": "^7.0.2",
"#testing-library/user-event": "^13.5.0",

The userEvent.setup() API is added in v14.0.0
There is a note in the doc user-event/intro
These docs describe user-event#14.

Related

How to resolve absolute path using Vite and ESlint in Svelte?

I have an import import icon from 'src/assets/icon.png', which I can't resolve.
I have "baseUrl": "." in jsconfig.json and
"settings": {
"import/resolver": {
"node": {
"paths": ["."]
}
}
}
in .eslintrc, but the thing is that if I use absolute import this way I get an error from Vite - [plugin:vite:import-analysis] Failed to resolve import "src/assets/icon.png" from "src\lib\Logo.svelte". Does the file exist?
At the same time if I add a forward slash before src in import like so import icon from '/src/assets/icon.png', it will work fine with NO error from vite, but eslint/no-unresolved-imports rule will give me a linting error.
I checked vite docs, but the only thing they offer is to use an alias for the path, which I'm not willing to do. Another workaround could be disabling the eslint rule, which is not an option for me either.
Question: Is there a way to resolve this path 'src/assets/icon.png' using "import/resolver" or vite's settings?
I found this page helpful in getting my setup working for absolute/aliased imports with Vite + React, but maybe it will be helpful to you too.
https://dev.to/abdeldjalilhachimi/how-to-avoid-long-path-import-using-react-with-ts-and-vite-4e2h
You don't have to define an alias for every folder - instead you use a dynamics alias that reads the directory name.
Add this to your vite.config.ts to set up the dynamic alias:
import * as path from 'path';
//...
export default defineConfig({
// ...config
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
},
});
Then in your tsconfig.json you can define the alias like so:
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
},
The baseUrl by itself almost worked well enough, but this solution seems to be more robust and lets me do exactly the kind of asset and module imports that you're talking about.
import logoPNG from '~/assets/logo.png';

How can I import AggregatorV3Interface

I'm trying to import AggregatorV3 but the file is nowhere to be found here is my code;
I'm sorry in advance i'm still a beginner programmer.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract Lottery {
address payable[] public players; //to keep track of all players, payable array
uint256 public usdEntryFee;
AggregatorV3Intefrace internal ethUsdPriceFeed;
constructor(address _priceFeedAddress) public {
usdEntryFree = 50 * (10**18);
ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress); //we need to pass the address of aggv3 in constructor
}
function enter() public payable {
//payable since we want them to pay in eth
//50 $ minimum
players.push(msg.sender);
}
function getEntranceFee() public view returns (uint256) {}
function startLottery() public {}
function endLottery() public {}
}
here is my Yaml file:
dependencies:
- smartcontractkit/chainlink-brownie-contracts#1.1.1
compiler:
solc:
remappings:
- '#chainlink=smartcontractkit/chainlink-brownie-contracts#1.1.1'
here is the error:
(base) marc#Marcs-MacBook-Pro smartcontract-lottery % brownie compile
Brownie v1.17.2 - Python development framework for Ethereum
Compiling contracts...
Solc version: 0.8.11
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
ParserError: Source "/Users/marc/.brownie/packages/smartcontractkit/chainlink-brownie-contracts#1.1.1/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol" not found: File not found.
--> contracts/Lottery.sol:4:1:
|
4 | import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I tried changing
compiler:
solc:
remappings:
- '#chainlink=smartcontractkit/chainlink-brownie-contracts#1.1.1'
to #0.2.1
I also tried changing solidity version to a newer version and it's not working
Thanks in advance!
I solved it by doing:
npm install #chainlink/contracts --save
and in the yaml file doing:
I solved it by replacing
import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
with
import "#chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
My mistake, cheers!
import "#chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
use v0.6 instead of v0.8
Hi I was also stuck in a similar problem. Make sure that the brownie-config.yaml file is not inside the test folder and is kept seperately. Hope this helps.
check the below image to see how I saved my brownie-config.yaml file

h is not defined error while running test cases in preact

I have a preact application which uses #testing-library/preact library for test cases. When I try to run a test for a component it throws an error stating that h is not defined. The app works without the import statement in the components but the test cases doesn't work. I get the it is required for converting jsx to h() calls. But is there any way to avoid it so that I don't have to import it in every component in the app ? PS: I tried to configure babel with this plugic babel-plugin-jsx-pragmatic for automatic import but it didn't work. This is my .babelrc file.
{
"plugins": [
["plugin-transform-react-jsx", {
"runtime": "automatic",
"importSource": "preact"
}]
]
}

How to use this module on my Ionic project?

I am just starting using Ionic framework recently. I have been trying to import this vcard module.
https://github.com/Heymdall/vcard
I am able to use it in normal javascript environment, but so far I am not able to use it in my .ts file.
What I have done are:
Adding the module using
npm install vcard-parser --save
npm install ajv#>=5.0.0 --save
Import it inside .ts file
import * as v from 'vcard-parser'
Then this is the result from console.log(v)
Object {}
proto
:
Object
constructor
:
function Object()
hasOwnProperty
:
function hasOwnProperty()
isPrototypeOf
:
function isPrototypeOf()
propertyIsEnumerable
:
function propertyIsEnumerable()
toLocaleString
:
function toLocaleString()
toString
:
function ()
valueOf
:
function valueOf()
defineGetter
:
function defineGetter()
defineSetter
:
function defineSetter()
lookupGetter
:
function lookupGetter()
lookupSetter
:
function lookupSetter()
get proto
:
function proto()
set proto
:
function proto()
I don't know how to use the module, such as calling function "parse" or "generate".
Could anybody please help me with an example please?
So their documentation on the install is not quite correct.
npm install vcard-parser
should change to
npm install vcard-parser --save
To save it to your package.json
I not 100% but it does not look like the code conforms to the component -> module pattern ( might be wrong here, just looks a bit different )
For most ionic/angular extentions/components you want to import it in your app.module.ts using the name declared in the package.json.
for example ionic-network would be
import { Network } from '#ionic-native/network';
Because in the package.json it is declared as a dependency as
"#ionic-native/network": "^4.1.0",
You can also import for a specific page and add it to the constructor.
Here is a post from the official documentation on installing 3rd party libraries
Based on how is vcard-parser tested, it should be like this:
declare var require: any;
var vCard = require('vcard-parser').vCard;
vCard.parse(raw);

how do you get flow to work with babel module-alias?

I am trying to get flow to type check my code but it is giving me an error when it can't find paths that have been rewritten using babel-plugin-module-alias.
I have unsuccessfully tried to use the resolve_dirname option in the flowconfig.
Can someone please tell me if it is possible to use this babel plugin with flow?
.babelrc
{
"plugins": [
"transform-flow-strip-types",
["module-alias", [
{ "src": "./app", "expose": "app" },
]]
]
}
.flowconfig
[options]
module.system.node.resolve_dirname=app
app/main.js
import bar from 'app/foo';
app/main.js:3
3: import bar from 'app/foo';
^^^^^^^^^^ app/foo. Required module not found
module.system.node.resolve_dirname actually tells Flow where to start resolving things from. If you want Flow to resolve starting from 'app', you need to point it one directory higher than app.
Alternatively, you can probably also use `module.name_mapper='^app/([a-z-A-Z0-9$_/]+)$' -> 'src/\1'
Here is how this can be achieved with module.name_mapper setting in .flowconfig [options]. Works in flow version 0.56.0
module.name_mapper='^app/\([-a-zA-Z0-9$_/]+\)$' -> '<PROJECT_ROOT>/src/\1'