Skip to content

Commit 3038c8d

Browse files
committed
chore: basic tests
1 parent fce7075 commit 3038c8d

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

jest.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
testEnvironment: 'node',
2+
testEnvironment: 'jsdom',
33
globals: {
44
'ts-jest': {
55
tsConfig: 'tsconfig.test.json'
@@ -10,9 +10,7 @@ module.exports = {
1010
},
1111
moduleFileExtensions: [
1212
"ts",
13-
"tsx",
1413
"js",
15-
"jsx",
1614
"json",
1715
"node",
1816
],

src/wrapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ import {Grid, UserConfig} from 'gridjs';
33
import $ from 'jquery';
44

55
$.fn.Grid = function (userConfig?: UserConfig) {
6-
new Grid(userConfig).render(this)
6+
const container = $(this);
7+
const grid = new Grid(userConfig);
8+
grid.render(container.get(0))
79
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`wrapper should render the table 1`] = `"<div id=\\"wrapper\\"><div role=\\"complementary\\" class=\\"gridjs gridjs-container gridjs-loading\\" style=\\"width: 100%;\\"><div class=\\"gridjs-loading-bar\\"></div><div class=\\"gridjs-head\\"></div><div class=\\"gridjs-wrapper\\" style=\\"width: 100%; height: auto;\\"><table role=\\"grid\\" class=\\"gridjs-table\\" style=\\"width: 100%; height: auto;\\"><tbody class=\\"gridjs-tbody\\"><tr class=\\"gridjs-tr\\"><td role=\\"alert\\" colspan=\\"0\\" class=\\"gridjs-td gridjs-message gridjs-loading\\">Loading...</td></tr></tbody></table></div><div class=\\"gridjs-footer\\"></div></div><div id=\\"gridjs-temp\\" class=\\"gridjs-temp\\"></div></div>"`;

tests/setup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as wrapper from '../src/wrapper';
2+
import $ from 'jquery';
3+
4+
// @ts-ignore
5+
global.$ = $;
6+
// @ts-ignore
7+
global.jQuery = $;
8+
// @ts-ignore
9+
global.wrapper = wrapper;

tests/wrapper.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="../src/jquery.d.ts"/>
2+
3+
import { Grid } from 'gridjs';
4+
5+
describe('wrapper', () => {
6+
it('should call the render method', () => {
7+
document.body.innerHTML = '<div id="wrapper"></div>';
8+
9+
const grid = jest.spyOn(Grid.prototype, 'render');
10+
11+
$('div#wrapper').Grid({
12+
data: [[1, 2, 3]]
13+
});
14+
15+
expect(grid).toBeCalled();
16+
});
17+
18+
it('should render the table', () => {
19+
document.body.innerHTML = '<div id="wrapper"></div>';
20+
21+
$('div#wrapper').Grid({
22+
data: [[1, 2, 3]]
23+
});
24+
25+
expect(document.body.innerHTML).toMatchSnapshot();
26+
});
27+
});

0 commit comments

Comments
 (0)