Skip to content

Commit

Permalink
test: Fixed broken imports
Browse files Browse the repository at this point in the history
  • Loading branch information
artalat committed Jul 20, 2019
1 parent baab4de commit 1d27e2b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 81 deletions.
16 changes: 6 additions & 10 deletions src/__tests__/getComponent.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { BlueBaseApp } from '../components/';
import { BlueBaseApp } from '../';
import React from 'react';
import TestRenderer from 'react-test-renderer';
import { getComponent } from '../getComponent';

describe('getComponent', () => {

test(`should render a text component`, (done) => {
test(`should render a text component`, done => {
const Text = getComponent('Text');

const component = TestRenderer.create(
Expand All @@ -23,8 +22,7 @@ describe('getComponent', () => {
});
});

test(`should render a button component`, (done) => {

test(`should render a button component`, done => {
const Button = getComponent('Button');

const component = TestRenderer.create(
Expand All @@ -42,7 +40,6 @@ describe('getComponent', () => {
});

test(`should throw an Error when no key is passed`, () => {

let message;

try {
Expand All @@ -55,7 +52,6 @@ describe('getComponent', () => {
});

test(`should throw an Error when there is not BlueBase context`, () => {

const Foo = getComponent('Foo');

let message;
Expand All @@ -65,8 +61,8 @@ describe('getComponent', () => {
message = error.message;
}

expect(message)
.toBe('Could not resolve component "Foo" in "getComponent" command. Reason: BlueBase context not found.');
expect(message).toBe(
'Could not resolve component "Foo" in "getComponent" command. Reason: BlueBase context not found.'
);
});

});
97 changes: 73 additions & 24 deletions src/components/Link/__tests__/Link.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlueBaseApp } from '../../index';
import { BlueBaseApp } from '../../../';
import { Link } from '../Link';
import React from 'react';
import { mount } from 'enzyme';
Expand All @@ -7,12 +7,10 @@ import { waitForElement } from 'enzyme-async-helpers';

let stubActions: any = {};

export const NavigationActions
= ({ children }: any) => renderChildrenWithProps(children, stubActions);
export const NavigationActions = ({ children }: any) =>
renderChildrenWithProps(children, stubActions);

describe('Link', () => {


beforeEach(() => {
stubActions = {
getParam: jest.fn(),
Expand All @@ -28,12 +26,11 @@ describe('Link', () => {
params: {},
routeName: '',
url: '',
}
},
};
});

test(`should call the navigate function with the given routeName`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -48,7 +45,15 @@ describe('Link', () => {
await waitForElement(wrapper as any, Link);

const onPress: any = wrapper.find('Link TouchableItem').prop('onPress');
onPress({ defaultPrevented: true, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: true,
preventDefault: () => {
return;
},
},
stubActions
);

expect(stubActions.navigate).toBeCalledTimes(1);
expect(stubActions.navigate).toBeCalledWith('Foo', undefined);
Expand All @@ -58,7 +63,6 @@ describe('Link', () => {
});

test(`should call the push function with the given routeName`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -73,7 +77,15 @@ describe('Link', () => {
await waitForElement(wrapper as any, Link);

const onPress: any = wrapper.find('Link TouchableItem').prop('onPress');
onPress({ defaultPrevented: true, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: true,
preventDefault: () => {
return;
},
},
stubActions
);

expect(stubActions.push).toBeCalledTimes(1);
expect(stubActions.push).toBeCalledWith('Foo', undefined);
Expand All @@ -83,7 +95,6 @@ describe('Link', () => {
});

test(`should call the push function with the given path`, async () => {

jest.mock('Platform', () => {
const Platform = (require as any).requireActual('Platform');
Platform.OS = 'web';
Expand All @@ -104,7 +115,15 @@ describe('Link', () => {
await waitForElement(wrapper as any, Link);

const onPress: any = wrapper.find('Link a').prop('onClick');
onPress({ defaultPrevented: true, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: true,
preventDefault: () => {
return;
},
},
stubActions
);

expect(stubActions.push).toBeCalledTimes(1);
expect(stubActions.push).toBeCalledWith({ path: '/foo' }, undefined);
Expand All @@ -114,7 +133,6 @@ describe('Link', () => {
});

test(`should call the replace function with the given path`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -129,7 +147,15 @@ describe('Link', () => {
await waitForElement(wrapper as any, Link);

const onPress: any = wrapper.find('Link a').prop('onClick');
onPress({ defaultPrevented: true, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: true,
preventDefault: () => {
return;
},
},
stubActions
);

expect(stubActions.replace).toBeCalledTimes(1);
expect(stubActions.replace).toBeCalledWith({ path: '/foo' }, undefined);
Expand All @@ -141,7 +167,6 @@ describe('Link', () => {
});

test(`should not do anything if event.defaultPrevented is true`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -156,14 +181,21 @@ describe('Link', () => {
await waitForElement(wrapper as any, Link);

const onPress: any = wrapper.find('Link a').prop('onClick');
onPress({ defaultPrevented: false, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: false,
preventDefault: () => {
return;
},
},
stubActions
);

expect(stubActions.replace).toBeCalledTimes(0);
expect(stubActions.push).toBeCalledTimes(0);
});

test(`should call the push function with the given path`, async () => {

const customOnPress = jest.fn();

const wrapper = mount(
Expand All @@ -177,7 +209,15 @@ describe('Link', () => {

// expect(wrapper.find('Link')).toMatchSnapshot();
const onPress: any = wrapper.find('Link a').prop('onClick');
onPress({ defaultPrevented: false, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: false,
preventDefault: () => {
return;
},
},
stubActions
);

expect(customOnPress).toBeCalledTimes(1);

Expand All @@ -186,7 +226,6 @@ describe('Link', () => {
});

test(`should not do anything if there is no path or routeName prop`, async () => {

const wrapper = mount(
<BlueBaseApp>
<Link />
Expand All @@ -197,7 +236,15 @@ describe('Link', () => {
await waitForElement(wrapper as any, Link);

const onPress: any = wrapper.find('Link TouchableItem').prop('onPress');
onPress({ defaultPrevented: false, preventDefault: () => { return; } }, stubActions);
onPress(
{
defaultPrevented: false,
preventDefault: () => {
return;
},
},
stubActions
);

expect(stubActions.push).toBeCalledTimes(0);
expect(stubActions.replace).toBeCalledTimes(0);
Expand All @@ -207,7 +254,6 @@ describe('Link', () => {
});

test(`should not render anything if component prop is null`, async () => {

const wrapper = mount(
<BlueBaseApp>
<Link component={null as any} />
Expand All @@ -217,9 +263,12 @@ describe('Link', () => {
// Wait for render
await waitForElement(wrapper as any, Link);

expect(wrapper.find('Link').last().children().length).toBe(0);
expect(
wrapper
.find('Link')
.last()
.children().length
).toBe(0);
// expect(wrapper).toMatchSnapshot();
});

});

16 changes: 4 additions & 12 deletions src/components/Redirect/__tests__/Redirect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlueBaseApp } from '../../index';
import { BlueBaseApp } from '../../../';
import React from 'react';
import { Redirect } from '../Redirect';
import { mount } from 'enzyme';
Expand All @@ -7,12 +7,10 @@ import { waitForElement } from 'enzyme-async-helpers';

let stubActions: any = {};

export const NavigationActions
= ({ children }: any) => renderChildrenWithProps(children, stubActions);
export const NavigationActions = ({ children }: any) =>
renderChildrenWithProps(children, stubActions);

describe('Redirect', () => {


beforeEach(() => {
stubActions = {
getParam: jest.fn(),
Expand All @@ -28,12 +26,11 @@ describe('Redirect', () => {
params: {},
routeName: '',
url: '',
}
},
};
});

test(`should call the replace function with the given routeName`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -56,7 +53,6 @@ describe('Redirect', () => {
});

test(`should call the replace function with the given path`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -79,7 +75,6 @@ describe('Redirect', () => {
});

test(`should call the push function with the given routeName`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -102,7 +97,6 @@ describe('Redirect', () => {
});

test(`should not do anything if there is no routeName or path prop`, async () => {

const components = {
NavigationActions,
};
Expand All @@ -121,6 +115,4 @@ describe('Redirect', () => {

expect(stubActions).toMatchSnapshot();
});

});

Loading

0 comments on commit 1d27e2b

Please sign in to comment.