Asynchronous test expects corrections

This commit is contained in:
Juraj Matuš 2017-09-06 15:31:04 +02:00
parent 921f2527c5
commit c6b96a5ab9
3 changed files with 22 additions and 18 deletions

View File

@ -105,8 +105,9 @@ describe('MenuContext', () => {
<MenuContext />
);
const { menuRegistry, menuActions } = instance.getChildContext();
initOutput.props.onLayout(defaultLayout);
menuRegistry.subscribe(menu1);
menuActions.openMenu('menu1').then(() => {
return menuActions.openMenu('menu1').then(() => {
expect(menuActions.isMenuOpen()).toEqual(true);
expect(menu1._getOpened()).toEqual(true);
initOutput.props.onLayout(defaultLayout);
@ -129,16 +130,16 @@ describe('MenuContext', () => {
const { menuRegistry, menuActions } = instance.getChildContext();
initOutput.props.onLayout(defaultLayout);
menuRegistry.subscribe(menu1);
menuActions.openMenu('menu1');
menuActions.closeMenu().then(() => {
expect(menuActions.isMenuOpen()).toEqual(false);
expect(menu1.props.onClose).toHaveBeenCalled();
const output = renderer.getRenderOutput();
const [ components, backdrop, options ] = output.props.children;
expect(components.type).toEqual(View);
expect(backdrop).toBeFalsy();
expect(options).toBeFalsy();
});
return menuActions.openMenu('menu1').then(() =>
menuActions.closeMenu().then(() => {
expect(menuActions.isMenuOpen()).toEqual(false);
expect(menu1.props.onClose).toHaveBeenCalled();
const output = renderer.getRenderOutput();
const [ components, backdrop, options ] = output.props.children;
expect(components.type).toEqual(View);
expect(backdrop).toBeFalsy();
expect(options).toBeFalsy();
}));
});
it('should toggle menu', () => {
@ -183,7 +184,7 @@ describe('MenuContext', () => {
);
const { menuRegistry, menuActions } = instance.getChildContext();
menuRegistry.subscribe(menu1);
menuActions.openMenu('menu1').then(() => {
return menuActions.openMenu('menu1').then(() => {
expect(menuActions.isMenuOpen()).toEqual(true);
const [ components, backdrop, options ] = output.props.children;
// on layout has not been not called
@ -200,7 +201,7 @@ describe('MenuContext', () => {
const { menuRegistry, menuActions } = instance.getChildContext();
initOutput.props.onLayout(defaultLayout);
menuRegistry.subscribe(menu1);
menuActions.openMenu('menu1').then(() => {
return menuActions.openMenu('menu1').then(() => {
const output = renderer.getRenderOutput();
expect(output.props.children.length).toEqual(3);
const options = output.props.children[2];
@ -230,7 +231,7 @@ describe('MenuContext', () => {
const { menuRegistry, menuActions } = instance.getChildContext();
initOutput.props.onLayout(defaultLayout);
menuRegistry.subscribe(menu1);
menuActions.openMenu('menu1').then(() => {
return menuActions.openMenu('menu1').then(() => {
const output = renderer.getRenderOutput();
expect(output.props.children.length).toEqual(3);
const backdrop = output.props.children[1];

View File

@ -1,10 +1,10 @@
import utils from 'react-addons-test-utils';
import ShallowRenderer from 'react-test-renderer/shallow';
/**
* Renders component and returns instance object and rendered output.
*/
export function render(Component, ctx) {
const renderer = utils.createRenderer();
const renderer = new ShallowRenderer();
renderer.render(Component, ctx);
const instance = renderer._instance._instance;
const output = renderer.getRenderOutput();

View File

@ -25,7 +25,10 @@
".*": "<rootDir>/node_modules/babel-jest"
},
"testRegex": ".*-test.js",
"testPathIgnorePatterns": ["/node_modules/", "<rootDir>/examples/"],
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/examples/"
],
"moduleFileExtensions": [
"js"
],
@ -55,8 +58,8 @@
"mocha": "^3.3.0",
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-addons-test-utils": "^15.5.1",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.6.1",
"sinon": "^2.2.0"
}
}