Skip to content

Commit cccd6ea

Browse files
committed
Components structure tests
1 parent 8ddc9a9 commit cccd6ea

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

__tests__/components/CategoriesHeader.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ describe('CategoriesHeader Component', () => {
4040
});
4141
});
4242

43-
describe('Component strucuture', () => {
43+
describe('Component structure', () => {
4444
it('Should render 2 categories', () => {
4545
expect(wrapper.root.findAllByType('Text').length).toBe(2);
4646
});
47+
48+
it('Should render correct titles', () => {
49+
expect(wrapper.root.findAllByType('Text')[0].props.children).toEqual('T-shirt');
50+
});
4751
});
48-
});
52+
});

__tests__/components/ProductsList.spec.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,56 @@ const INITIAL_STATE = {
3232
price: 125.36
3333
}
3434
],
35-
},
35+
},
3636
categories: {
3737
currentId: 3,
3838
}
3939
};
4040

41+
const STATE_WITHOUT_ITEMS = {
42+
products: {
43+
items: [],
44+
},
45+
categories: {
46+
currentId: 3,
47+
}
48+
}
49+
4150
const navigation = { navigate: jest.fn() };
51+
4252
let wrapper;
53+
let wrapperWithoutItems;
4354

4455
beforeEach(() => {
4556
wrapper = ReactTestRender.create(
4657
<Provider store={mockStore(INITIAL_STATE)}>
4758
<ProductsList navigation={navigation} />
4859
</Provider>,
4960
);
61+
62+
wrapperWithoutItems = ReactTestRender.create(
63+
<Provider store={mockStore(STATE_WITHOUT_ITEMS)}>
64+
<ProductsList navigation={navigation} />
65+
</Provider>,
66+
);
5067
});
5168

5269
describe('ProductsList Component', () => {
5370
describe('Smoke tests', () => {
5471
it('Should render ProductsList component correctly', () => {
5572
expect(wrapper.toJSON()).toMatchSnapshot();
56-
});
73+
});
5774
});
5875

59-
describe('Component strucuture', () => {
76+
describe('Component structure', () => {
6077
it('Should render 3 items', () => {
6178
expect(wrapper.root.findAllByType('TouchableOpacity').length).toBe(3);
79+
expect(wrapper.root.findAllByType('Image').length).toBe(3);
80+
expect(wrapper.root.findAllByType('Text').length).toBe(9);
6281
});
63-
});
82+
83+
it('Should render no items', () => {
84+
expect(wrapperWithoutItems.root.findAllByType('TouchableOpacity').length).toBe(0);
85+
});
86+
});
6487
});

0 commit comments

Comments
 (0)