-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when update to version 8 broke my application #366
Comments
With version 8, I had to use import queryString from 'query-string'
queryString.stringify(queryParams) |
Even I am facing the same issue. After upgrading to version 8 , my tests start to fail. I tried all the steps https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c but none of them worked. Can anyone suggest solution to it? |
@sindresorhus I am not sure how your response answers the question. I am probably being a little dense. Unlike @lukasvice, I was already importing @jadir-junior if you resolved this, please respond with your fix. Thank you! |
@jadir-junior @varshagada @cbrenner04 In your main Jest preset file you should have smth like this:
Basically I had to add not only |
I got it solved by mocking the Query-string in my test files. sample.test.js import queryString from 'query-string' jest.mock('query-string' , () => ({ Thankyou |
Similar to @smajl 's solution. You can also add the following section to your "jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
],
"transformIgnorePatterns": [
"node_modules/(?!(@react-native|react-native|decode-uri-component|filter-obj|split-on-first|query-string)/)"
]
} Note: I'm using React-Native, if you aren't, you'll have to tweak it a bit. |
This worked for me, thanks |
I'm also having this issue. I can't mock this out as it's critical to my app and needs testing. Adding @sindresorhus any help on this would be really appreciated 🙏 The link you provided above doesn't work, and this issue shouldn't really be closed. |
I had to install transformIgnorePatterns: [
'node_modules/(?!(query-string|decode-uri-component|split-on-first|filter-obj)/)',
],
babelConfig: {
plugins: ['@babel/plugin-proposal-private-methods'],
}, |
In my case, I just added the following code in the jest.config.js
|
The jest.mock("query-string" , () => ({
__esModule: true,
default: {
parse :jest.fn(),
stringify: jest.fn()
}
})) |
For some PNPM hitchhikers who getting this problem again when migrated PNPM form npm. You need to add const esModules = [
'other_modules_based_on_your_needs',
// but mainly those 4 bellow
'query-string',
'decode-uri-component',
'split-on-first',
'filter-obj',
];
module.exports = {
...
transformIgnorePatterns: esModules.length ? [`/node_modules/.pnpm/(?!${esModules.join('|')})`] : [],
...
} |
I had done this in my side ^ + the |
For those using NextJS 13 and mocking isn't an option, this did the trick for me: vercel/next.js#36077 (comment) |
I solved this a different way: by relying on the URLSearchParams web API instead. This allowed me to remove the The biggest hangup I had was that URLSearchParams doesn't support the bracket array syntax, but it's pretty easy to find ways around that via Google or ChatGPT or whatever. |
This workaround works for me. My usage is very simple, so I just replace const queryString = require('query-string');
const parsed = queryString.parse(location.search);
const jdata = parsed['jdata']; with const parsed = new URLSearchParams(location.search);
const jdata = parsed.get("jdata"); |
None of this worked for me. I, too, only want to get array brackets. Here is how to do so natively in Node.js. const params = new URLSearchParams();
params.append('barcode', barcode);
storeIDs.forEach((storeID) => params.append('store_ids[]', storeID));
// barcode=04003100&store_ids[]=775
const qs = params.toString(); |
@Chanki-Min Thank you so much for this, I was losing my mind!!! |
In version 7.1.3 I can import stringify
now in version ^8 a I can't, and when I try to refactor the code to import queryString and use queryString.stringify my tests with jest broken like that:
The text was updated successfully, but these errors were encountered: