Skip to content

Commit

Permalink
Tests refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jan 28, 2019
1 parent 6934a1c commit 78692fc
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 382 deletions.
129 changes: 63 additions & 66 deletions src/test/noSuspense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,90 @@
'use strict';

// Modules
const React = require('react');
const React = require('react'),
{expect} = require('chai');

// Imports
const {makeTests} = require('./utils');
const {itRendersWithSyncCompare} = require('./utilsNew');

// Tests

// TODO Refactor these tests to use `utilsNew` test helpers instead
describe('Without Suspense', function() {
describe('plain', function() {
describe('string', makeTests(
() => 'text',
'text'
));
itRendersWithSyncCompare('string', async ({render}) => {
const e = 'text';
const h = await render(e);
expect(h).to.equal('text');
});

describe('div', makeTests(
() => <div>text</div>,
({openTag}) => `<div${openTag}>text</div>`
));
itRendersWithSyncCompare('div', async ({render, openTag}) => {
const e = <div>text</div>;
const h = await render(e);
expect(h).to.equal(`<div${openTag}>text</div>`);
});

describe('nested divs', makeTests(
() => <div><div>text</div></div>,
({openTag}) => `<div${openTag}><div>text</div></div>`
));
itRendersWithSyncCompare('nested divs', async ({render, openTag}) => {
const e = <div><div>text</div></div>;
const h = await render(e);
expect(h).to.equal(`<div${openTag}><div>text</div></div>`);
});
});

describe('in function component', function() {
describe('string', makeTests(
() => {
const Comp = () => 'text';
return <Comp/>;
},
'text'
));
itRendersWithSyncCompare('string', async ({render}) => {
const Comp = () => 'text';
const e = <Comp/>;
const h = await render(e);
expect(h).to.equal('text');
});

describe('div', makeTests(
() => {
const Comp = () => <div>text</div>;
return <Comp/>;
},
({openTag}) => `<div${openTag}>text</div>`
));
itRendersWithSyncCompare('div', async ({render, openTag}) => {
const Comp = () => <div>text</div>;
const e = <Comp/>;
const h = await render(e);
expect(h).to.equal(`<div${openTag}>text</div>`);
});

describe('nested divs', makeTests(
() => {
const Comp = () => <div><div>text</div></div>;
return <Comp/>;
},
({openTag}) => `<div${openTag}><div>text</div></div>`
));
itRendersWithSyncCompare('nested divs', async ({render, openTag}) => {
const Comp = () => <div><div>text</div></div>;
const e = <Comp/>;
const h = await render(e);
expect(h).to.equal(`<div${openTag}><div>text</div></div>`);
});
});

describe('in class component', function() {
describe('string', makeTests(
() => {
class Comp extends React.Component {
render() {
return 'text';
}
itRendersWithSyncCompare('string', async ({render}) => {
class Comp extends React.Component {
render() {
return 'text';
}
return <Comp/>;
},
'text'
));
}
const e = <Comp/>;
const h = await render(e);
expect(h).to.equal('text');
});

describe('div', makeTests(
() => {
class Comp extends React.Component {
render() {
return <div>text</div>;
}
itRendersWithSyncCompare('div', async ({render, openTag}) => {
class Comp extends React.Component {
render() {
return <div>text</div>;
}
return <Comp/>;
},
({openTag}) => `<div${openTag}>text</div>`
));
}
const e = <Comp/>;
const h = await render(e);
expect(h).to.equal(`<div${openTag}>text</div>`);
});

describe('nested divs', makeTests(
() => {
class Comp extends React.Component {
render() {
return <div><div>text</div></div>;
}
itRendersWithSyncCompare('nested divs', async ({render, openTag}) => {
class Comp extends React.Component {
render() {
return <div><div>text</div></div>;
}
return <Comp/>;
},
({openTag}) => `<div${openTag}><div>text</div></div>`
));
}
const e = <Comp/>;
const h = await render(e);
expect(h).to.equal(`<div${openTag}><div>text</div></div>`);
});
});
});
Loading

0 comments on commit 78692fc

Please sign in to comment.