Skip to content

Commit dc5756d

Browse files
committed
tests
1 parent 29e7e64 commit dc5756d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"displayName": "Unit",
4949
"preset": "@activewidgets/testing",
5050
"moduleNameMapper": {
51-
"@activewidgets/components": "<rootDir>/jquery",
51+
"@activewidgets/components": "<rootDir>/js",
5252
"@activewidgets/testing": "<rootDir>/test/adapter/jquery.js"
5353
}
5454
},

test/adapter/jquery.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
import {getQueriesForElement} from '@testing-library/dom';
3+
import '@activewidgets/components';
4+
import $ from 'jquery';
5+
6+
7+
export function render(component, props){
8+
9+
let baseElement = document.body,
10+
container = baseElement.appendChild(document.createElement('div')),
11+
el = container.appendChild(document.createElement(component));
12+
13+
let i, $el = $(el);
14+
15+
for (i in props){
16+
if (i.slice(0, 2) == 'on'){
17+
$el.on(i.slice(2).toLowerCase(), event => props[i](event.detail));
18+
}
19+
else {
20+
$el.prop(i, props[i]);
21+
}
22+
}
23+
24+
$el.mount();
25+
26+
return {
27+
container,
28+
baseElement,
29+
...getQueriesForElement(baseElement)
30+
}
31+
};
32+
33+
34+
export function cleanup(){
35+
document.body.innerHTML = '';
36+
};
37+
38+
39+
if (typeof afterEach === 'function') {
40+
afterEach(cleanup);
41+
}
65 KB
Loading

0 commit comments

Comments
 (0)