|
|
@@ -1,16 +1,16 @@
|
|
|
import * as React from 'react';
|
|
|
-import {shallow, mount} from 'enzyme';
|
|
|
+import {shallow, mount, ReactWrapper, ShallowWrapper} from 'enzyme';
|
|
|
|
|
|
import PokemonShow from 'packs/frontend/components/pages/pokemon/show';
|
|
|
import {instance} from 'packs/frontend/api';
|
|
|
|
|
|
-import {Route, StaticRouter} from 'react-router-dom';
|
|
|
+import {StaticRouter} from 'react-router-dom';
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
|
|
const defaultProps = {
|
|
|
match: {
|
|
|
params: {
|
|
|
- id: 1,
|
|
|
+ id: '1',
|
|
|
},
|
|
|
url: '/pokemon/show/1',
|
|
|
path: '',
|
|
|
@@ -21,11 +21,11 @@ const defaultProps = {
|
|
|
pokemon: {},
|
|
|
};
|
|
|
|
|
|
-function setup(props = defaultProps) {
|
|
|
+function setup(props = defaultProps): ShallowWrapper {
|
|
|
return shallow(<PokemonShow {...props} />);
|
|
|
}
|
|
|
|
|
|
-function mountSetup(props = defaultProps) {
|
|
|
+function mountSetup(props = defaultProps): ReactWrapper {
|
|
|
return mount(
|
|
|
<StaticRouter>
|
|
|
<PokemonShow {...props} />
|
|
|
@@ -33,22 +33,26 @@ function mountSetup(props = defaultProps) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-describe('<PokemonShow />', () => {
|
|
|
- it('sets default state', () => {
|
|
|
+describe('<PokemonShow />', (): void => {
|
|
|
+ it('sets default state', (): void => {
|
|
|
const wrapper = setup();
|
|
|
expect(wrapper.state('pokemon')).toEqual({id: null, nickname: null});
|
|
|
});
|
|
|
|
|
|
- describe('componentDidMount()', () => {
|
|
|
+ describe('componentDidMount()', (): void => {
|
|
|
let mock;
|
|
|
- beforeEach(() => {
|
|
|
- mock = new MockAdapter(instance);
|
|
|
- });
|
|
|
- afterEach(() => {
|
|
|
- mock.restore();
|
|
|
- });
|
|
|
+ beforeEach(
|
|
|
+ (): void => {
|
|
|
+ mock = new MockAdapter(instance);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ afterEach(
|
|
|
+ (): void => {
|
|
|
+ mock.restore();
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
- it('persists fetched pokemon to state', async () => {
|
|
|
+ it('persists fetched pokemon to state', async (): Promise<any> => {
|
|
|
const mockData = {
|
|
|
id: 1,
|
|
|
nickname: 'Bulbasaur',
|