Skip to content

Commit

Permalink
test(directives): add v-skip directive test
Browse files Browse the repository at this point in the history
  • Loading branch information
Masquerade-Circus committed Mar 27, 2020
1 parent 280cf58 commit 6d50ecc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ function valyrian() {
});
v.directive('v-html', (html, vnode) => {
vnode.dom.innerHTML = html;
vnode.props['v-skip'] = true;
vnode.props[skip] = true;
});
v.directive('v-text', (text, vnode) => {
vnode.dom.textContent = text;
vnode.props['v-skip'] = true;
vnode.props[skip] = true;
});

return v;
Expand Down
25 changes: 25 additions & 0 deletions test/directives_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,30 @@ describe('Directives', () => {
});
});

/**
* The v-skip directive is used to prevent the patch of children vnodes but allow the patch of dom attributes
* Its main use will be along with other custom directives to prevent the children patch step
*/
describe('v-skip', () => {
it('should prevent child patching step', () => {
let Store = {
id: 'example',
children: 'Hello world'
};

let Component = () => <div v-skip id={Store.id}>{Store.children}</div>;
let result = v.mount('body', Component);
expect(result).toEqual('<div id="example"></div>');

Store.id = 'example-updated';
Store.children = 'Hello John Doe';

let result2 = v.update();

expect(result2).toEqual('<div id="example-updated"></div>');
});
});

/**
* The v-html directive is used to direct raw html render to increase performance
* We can use this directive to replace the v.trust use like in this test
Expand Down Expand Up @@ -430,5 +454,6 @@ describe('Directives', () => {
expect(result).toEqual('<div>Hello world</div>');
});
});

});

0 comments on commit 6d50ecc

Please sign in to comment.