Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Sep 1, 2023
1 parent cb0eeec commit da181d1
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion test/browser/fragments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ describe('Fragment', () => {
expect(scratch.innerHTML).to.equal('<div>Hello</div>');
});

it('should preserver order', () => {
it('should preserve order for fragment switching', () => {
let set;
class Foo extends Component {
constructor(props) {
Expand Down Expand Up @@ -677,6 +677,79 @@ describe('Fragment', () => {
);
});

it('should preserve order for nested fragment switching w/ child return', () => {
let set;
const Wrapper = ({ children }) => <Fragment>{children}</Fragment>;
class Foo extends Component {
constructor(props) {
super(props);
this.state = { isLoading: true, data: null };
set = this.setState.bind(this);
}
render(props, { isLoading, data }) {
return (
<Fragment>
<div>HEADER</div>
{isLoading ? <div>Loading...</div> : null}
{data ? <div>Content: {data}</div> : null}
</Fragment>
);
}
}

render(
<Wrapper>
<Foo />
</Wrapper>,
scratch
);
expect(scratch.innerHTML).to.equal(
'<div>HEADER</div><div>Loading...</div>'
);

set({ isLoading: false, data: 2 });
rerender();
expect(scratch.innerHTML).to.equal(
'<div>HEADER</div><div>Content: 2</div>'
);
});

it('should preserve order for nested fragment switching', () => {
let set;
const Wrapper = () => (
<Fragment>
<Foo />
</Fragment>
);
class Foo extends Component {
constructor(props) {
super(props);
this.state = { isLoading: true, data: null };
set = this.setState.bind(this);
}
render(props, { isLoading, data }) {
return (
<Fragment>
<div>HEADER</div>
{isLoading ? <div>Loading...</div> : null}
{data ? <div>Content: {data}</div> : null}
</Fragment>
);
}
}

render(<Wrapper />, scratch);
expect(scratch.innerHTML).to.equal(
'<div>HEADER</div><div>Loading...</div>'
);

set({ isLoading: false, data: 2 });
rerender();
expect(scratch.innerHTML).to.equal(
'<div>HEADER</div><div>Content: 2</div>'
);
});

it('should preserve state with reordering in multiple levels', () => {
function Foo({ condition }) {
return condition ? (
Expand Down

0 comments on commit da181d1

Please sign in to comment.