Native stack is only available if React Native Screens is enabled - react-native

When I try to run tests for storyshots with native screens enabled for react-navigation I get this:
Native stack is only available if React Native Screens is enabled.
15 | const getRenderedTree = (story: any) => {
16 | const storyElement = story.render()
> 17 | const tree = renderer.create(storyElement)
| ^
18 |
19 | return tree
20 | }

Related

React native None of these files exist: error?

the path of the file is correct but I get the following error
`None of these files exist:
* src\pages\Test(.native|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
* src\pages\Test\index(.native|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
7 |
8 | import React from 'react';
> 9 | import Test from './src/pages/Test';
| ^
10 |
11 | function App() {
12 | return (]`
FOLDER STRUCTURE;
show
created new project.
import react from 'react';
import {View, Text} from 'react-native';
export default function Test() {
return (
<View>
<Text>Test</Text>
</View>
);
}

istanbul generates empty report

I wanted to launch istanbul in my project, however no matter what I do reports shows only zeros. like below :
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Even though it shows above the coverage report list of the test that passed. For simplicity I created super simple project for replication where I have only one function in indentity.js file :
export const identity = (x) => x;
and one simple test licated in test.js file
import { identity } from "./identity.js";
import assert from "assert";
describe("identity", function () {
it("should return passed argument", () => {
assert.equal(identity(1), 1);
assert.equal(identity("string"), "string");
assert.deepEqual(identity({ a: 1 }), { a: 1 });
});
});
and after I run nyc mocha I expect to see 100% coverage but what I have is the same table with zeros.
Is there some settings I missed to see proper coverage report ?
Thx in advance.

Invalid array length

I'm trying to test this component on vue, but when I run the test I get the message down bellow:
RangeError: Invalid array length
96 | this.changeLogs.marketConfiguration.productTypes
97 | );
> 98 | return [
| ^
99 | ...new Set(
100 | productTypes.flatMap((productType) => productType.domains || [])
101 | )
I'm using Jest, with vue-test-utils.
And this is the function:
affectedDomains(): string {
const productTypes: ProductTypeConfiguration[] = Object.values(
this.changeLogs.marketConfiguration.productTypes
);
return [
...new Set(
productTypes.flatMap((productType) => productType.domains || [])
)
].join(', ');
}
Found a solution, in my case was to set the "downlevelIteration": true, on tsconfig.json.
Downleveling is TypeScript’s term for transpiling to an older version
of JavaScript. This flag is to enable support for a more accurate
implementation of how modern JavaScript iterates through new concepts
in older JavaScript runtimes.
More info

Cannot read properties of undefined (reading 'toString') in Jest React Native

TypeError: Cannot read properties of undefined (reading 'toString')
15 | let TempLastname = route.params.lastName
16 | let TempAge = route.params.age
> 17 | let StringAge = TempAge.toString()
| ^
18 | let TempPhoto = route.params.photo
19 | const [Error,setError] = useState('')
20 | const [disableButton,setDisableButton] = useState(true)
at EditContact (components/screens/EditContact.js:17:29)
at renderWithHooks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6016:18)
at mountIndeterminateComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8744:13)
at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9966:16)
at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13800:12)
at workLoopSync (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13728:5)
at renderRootSync (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13691:7)
at performSyncWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13404:18)
at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2537:26
at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12)
I tried to make a snap test using jest, but i found this problem, can someone help me?
the code test :
describe('Testing Edit Contact snaps',()=>{
test('render corretly',()=>{
const mockedparams = {
route:{params : {itemID:'route.params.itemID'}},
navigation:''
}
const tree = create(
<Provider store={store}>
<EditContact navigation={navigation} {...mockedparams}/>
</Provider>
).toJSON()
expect(tree).toMatchSnapshot();
})
i have found the same problem in stackoverflow but different error, can some one fix it? thanks a lot

Sinon test error with whois-json

I have a service API which up until recently used the whois library to get data.
I use sinon to test the API:
const mockWhoisLookup = sinon.mock(whois);
mockWhoisLookup
.expects('lookup')
.once()
.withArgs('deals.dk')
.callsFake((domain, callback) => {
callback(undefined, whoisSampleResponse);
});
I've decided to use whois-json instead as it provides a 'cleaner' output.
The issue is that when I now run the test it gives me an error output:
TypeError: Attempted to wrap undefined property lookup as function
61 | const mockWhoisLookup = sinon.mock(whois);
62 | mockWhoisLookup
> 63 | .expects('lookup')
64 | .once()
65 | .withArgs('deals.dk')
66 | .callsFake((domain, callback) => {
How do I solve this issue?