Closed NikitaSergeevich closed 7 years ago
This isnt an issue with react-native-mock, more with how you're asserting. A rendered component will never equal 'true', it's a component. If youre after a simple check, you can use .to.be.OK;, or even better, check that the right number render with .to.have.lengthOf(1);.
Closing, non-issue
So guys, maybe you can put some light on situation when I trying to test more complicated component to which I provide a mocked store in a following way:
import mockery from "mockery";
import 'babel-polyfill';
import reactNativeSvgMock from "react-native-svg-mock";
mockery.enable();
mockery.registerMock("react-native-svg", reactNativeSvgMock);
var DeskScreen = require( '../app/containers/DeskScreen/DeskScreen');
import React, {View, Text, StyleSheet, TouchableHighlight} from 'react-native';
import {Provider} from 'react-redux';
import {shallow, render, mount} from 'enzyme';
import {expect} from 'chai';
import configureStore from 'redux-mock-store';
import reducer from "../app/reducers";
import Button from "../app/containers/Common/Button";
import ButtonWithNoFlex from "../app/containers/Common/ButtonWithNoFlex";
import Drawer from 'react-native-drawer';
var DeskHeader = require('../app/containers/DeskHeader/DeskHeader');
const mockStore = configureStore([]);
describe('<Test />', () => {
it('it should render 1 view component', () => {
const store = mockStore(reducer);
var comp = shallow(
<Provider store={store}>
<DeskScreen/>
</Provider>
);
expect(comp.find(Drawer)).to.have.length(1);
});
});
Unfortunately with that little information, it's impossible to help you. This also doesnt seem like an issue with react-native-mock at all. I suggest seeking help in a less specific location such as Stack Overflow
I'm quite new to react and react-native testing, after some research I decided to use mocha and enzyme to test my components. So i used react-native-mockery, redux-mock-store and react-native-svg-mock in order to run any test. my TestComponent.js file has following code:
but I get following error:
0 passing (984ms) 1 failing
1) it should render 1 view component:
AssertionError: expected { Object (root, unrendered, ...) } to equal true
at Context. (test/TestComponent.js:24:38)
Can anybody help me to fix it? ButtonWithNoFlex component is just simple 'dumb' component which looks like that: