Skip to content

Commit 0fc887c

Browse files
committed
[ADD]🚀 getGifs with Fetch tests added
1 parent 64170f0 commit 0fc887c

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
import GifGridItem from '../../components/GifGridItem';
5+
6+
describe('Tests GifGridItem component', () => {
7+
const url = 'https://localhost:8080/something.gif';
8+
const title = 'something';
9+
10+
let wrapper = shallow(<GifGridItem url={url} title={title} />);
11+
12+
beforeEach(() => {
13+
wrapper = shallow(<GifGridItem url={url} title={title} />);
14+
});
15+
16+
test('Should display correctly', () => {
17+
expect(wrapper).toMatchSnapshot();
18+
});
19+
20+
describe('Tests className attribute', () => {
21+
test('Should have card in className', () => {
22+
const text = wrapper.find('div').prop('className');
23+
expect(text.includes('card')).toBe(true);
24+
});
25+
26+
test('Should have animate__animated and animate__fadeIn in className', () => {
27+
const text = wrapper.find('.card').prop('className');
28+
expect(text.includes('animate__animated')).toBe(true);
29+
expect(text.includes('animate__fadeIn')).toBe(true);
30+
});
31+
});
32+
33+
describe('Tests url attribute', () => {
34+
const text = wrapper.find('.card img').prop('src');
35+
36+
test('Should have a sub-string with https:// text', () => {
37+
expect(text.includes('https://')).toBe(true);
38+
});
39+
40+
test('Should have a something with .gif', () => {
41+
expect(text.includes('.gif')).toBe(true);
42+
});
43+
44+
test('Should have a alt with something text', () => {
45+
const text = wrapper.find('.card img').prop('alt');
46+
expect(text).toBe(title);
47+
});
48+
});
49+
50+
test('Should have a title with something text', () => {
51+
const text = wrapper.find('.card p').text();
52+
expect(text).toBe(title);
53+
});
54+
});
55+
56+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Tests GifGridItem component Should display correctly 1`] = `
4+
<div
5+
className="card animate__animated animate__fadeIn"
6+
>
7+
<img
8+
alt="something"
9+
src="https://localhost:8080/something.gif"
10+
/>
11+
<p>
12+
something
13+
</p>
14+
</div>
15+
`;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
import { getGifs } from '../../helpers';
5+
6+
describe('Tests getGifs with Fetch', () => {
7+
test('Should return a length of 15', async () => {
8+
const gifs = await getGifs('Dragon Ball');
9+
expect(gifs.length).toBe(15);
10+
});
11+
12+
test('Should return a length of 0', async () => {
13+
const gifs = await getGifs('');
14+
expect(gifs.length).toBe(0);
15+
});
16+
17+
test('Should not have " GIF" text string in the title', async () => {
18+
const gifs = await getGifs('Dragon Ball');
19+
const allTitle = gifs.reduce((acc, gif) => `${acc} ${gif.title}`, '');
20+
21+
expect(allTitle.includes(' GIF')).not.toBe(true);
22+
});
23+
});
24+

0 commit comments

Comments
 (0)