Skip to content

Commit

Permalink
test: whitelist tests for patch
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Oct 28, 2021
1 parent 3502890 commit 20ca4bc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const config: Config.InitialOptions = {
'!src/**/types/*',
'!src/**/schedule.ts',
'!src/**/jsx.ts',
'!src/**/patch.ts',
'!src/**/drivers/*',
],
};
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/__test__/patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe('.patch', () => {
document.body.textContent = '';
});

it('should remove text', () => {
const el = createElement('foo');
document.body.appendChild(el);
patch(el, undefined, 'foo');
expect(document.body.firstChild?.nodeValue).toEqual(undefined);
document.body.textContent = '';
});

it('should remove textContent if no children', () => {
const el = createElement(m('div'));

Expand Down Expand Up @@ -195,4 +203,18 @@ describe('.patch', () => {
expect((<HTMLElement>el2).id).toEqual('app');
expect((<HTMLElement>el2).isEqualNode(el1)).toBeTruthy();
});

it('should hard replace if different tag', () => {
const el1 = createElement(m('div'));
const el2 = patch(el1, m('a'));

expect(el2).toEqual(document.createElement('a'));
});

it('should return el if ignore is set', () => {
const el1 = createElement(m('div', { ignore: true }));
const el2 = patch(el1, m('a'));

expect(el2).toEqual(el1);
});
});

0 comments on commit 20ca4bc

Please sign in to comment.