Skip to content

Commit 85d6578

Browse files
authored
build(tools): add eslint configuration for tests with jest (#7)
1 parent 6078dbf commit 85d6578

15 files changed

+87
-41
lines changed

.eslintignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.github
2+
.husky
3+
dist
4+
example
5+
node_modules
6+
resources
7+
*lock*
8+
.*ignore
9+
*.css
10+
*.ico
11+
*.json
12+
*.html
13+
*.md
14+
*.yaml
15+
.editorconfig
16+
LICENSE

.eslintrc.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,33 @@
1313
"impliedStrict": true
1414
}
1515
},
16+
"plugins": ["prettier"],
1617
"extends": [
1718
"eslint:recommended",
1819
"airbnb-base",
1920
"plugin:import/recommended",
2021
"plugin:promise/recommended",
2122
"plugin:prettier/recommended"
2223
],
23-
"plugins": ["prettier"],
24+
"overrides": [
25+
{
26+
"files": ["**/__tests__/**/*.js", "**/?(*.)+(spec|test).js"],
27+
"env": {
28+
"jest": true
29+
},
30+
"settings": {
31+
"jest": {
32+
"version": 29
33+
}
34+
},
35+
"extends": [
36+
"plugin:jest/recommended",
37+
"plugin:jest/style",
38+
"plugin:jest-dom/recommended",
39+
"plugin:testing-library/dom"
40+
]
41+
}
42+
],
2443
"rules": {
2544
"prettier/prettier": "error",
2645
"consistent-return": "warn",

.lintstagedrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"src/*.js": ["pnpm run lint:tool:eslint --fix", "git add ."],
2+
"{__tests__,src}/**/*.js": ["pnpm run lint:tool:eslint --fix", "git add ."],
33
"**/*.{css,html,json,md}": ["pnpm run lint:tool:prettier --write", "git add ."]
44
}

.prettierignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
.*ignore
1+
.husky
2+
dist
3+
example
4+
node_modules
5+
resources
26
*lock*
7+
.*ignore
8+
*.ico
9+
*.js
10+
*.yaml
11+
.editorconfig
312
.github/PULL_REQUEST_TEMPLATE.md
4-
example/example.min.js

__tests__/cancel.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('cancel', () => {
3333
drake.start(item);
3434
drake.cancel();
3535

36-
expect(div.children.length).toEqual(1);
36+
expect(div.children).toHaveLength(1);
3737
expect(drake.dragging).toBeFalsy();
3838
});
3939

__tests__/container.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('container', () => {
66
const drake = dragula();
77

88
expect(Array.isArray(drake.containers)).toBeTruthy();
9-
expect(drake.containers.length).toEqual(0);
9+
expect(drake.containers).toHaveLength(0);
1010
});
1111

1212
it('drake reads containers from array argument', () => {
@@ -15,7 +15,7 @@ describe('container', () => {
1515
const drake = dragula(containers);
1616

1717
expect(drake.containers).toEqual(containers);
18-
expect(drake.containers.length).toEqual(1);
18+
expect(drake.containers).toHaveLength(1);
1919
});
2020

2121
it('drake reads containers from array in options', () => {
@@ -24,7 +24,7 @@ describe('container', () => {
2424
const drake = dragula({ containers });
2525

2626
expect(drake.containers).toEqual(containers);
27-
expect(drake.containers.length).toEqual(1);
27+
expect(drake.containers).toHaveLength(1);
2828
});
2929

3030
it('containers in options take precedent', () => {
@@ -33,6 +33,6 @@ describe('container', () => {
3333
const drake = dragula([], { containers });
3434

3535
expect(drake.containers).toEqual(containers);
36-
expect(drake.containers.length).toEqual(1);
36+
expect(drake.containers).toHaveLength(1);
3737
});
3838
});

__tests__/default.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ const dragula = require('../src/dragula');
33

44
describe('default', () => {
55
it('drake has sensible default options', () => {
6-
const options = dragula({}).options;
6+
const { options } = dragula({});
77

8-
expect(typeof options.moves).toEqual('function');
9-
expect(typeof options.accepts).toEqual('function');
10-
expect(typeof options.invalid).toEqual('function');
11-
expect(typeof options.isContainer).toEqual('function');
8+
expect(typeof options.moves).toBe('function');
9+
expect(typeof options.accepts).toBe('function');
10+
expect(typeof options.invalid).toBe('function');
11+
expect(typeof options.isContainer).toBe('function');
1212
expect(options.copy()).toBeFalsy();
1313
expect(options.revertOnSpill).toBeFalsy();
1414
expect(options.removeOnSpill).toBeFalsy();
15-
expect(options.direction).toEqual('vertical');
15+
expect(options.direction).toBe('vertical');
1616
expect(options.mirrorContainer).toEqual(document.body);
1717
});
1818
});

__tests__/destroy.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('destroy', () => {
3333
drake.start(item);
3434
drake.destroy();
3535

36-
expect(div.children.length).toEqual(1);
36+
expect(div.children).toHaveLength(1);
3737
expect(drake.dragging).toBeFalsy();
3838
});
3939

__tests__/drag.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('drag', () => {
154154
events.raise(item, 'pointerdown', { which: 1 });
155155
events.raise(item, 'pointermove', { which: 1 });
156156

157-
expect(item.className).toEqual('gu-transit');
157+
expect(item.className).toBe('gu-transit');
158158
});
159159

160160
it.skip('when dragging, body gets gu-unselectable class', () => {
@@ -167,7 +167,7 @@ describe('drag', () => {
167167
events.raise(item, 'pointerdown', { which: 1 });
168168
events.raise(item, 'pointermove', { which: 1 });
169169

170-
expect(document.body.className).toEqual('gu-unselectable');
170+
expect(document.body.className).toBe('gu-unselectable');
171171
});
172172

173173
it.skip('when dragging, element gets a mirror image for show', () => {
@@ -186,7 +186,7 @@ describe('drag', () => {
186186

187187
expect(item.className).toBe('gu-transit');
188188
expect(stubCloned).toHaveBeenCalledTimes(1);
189-
expect(stubCloned.mock.calls[0][0].className).toEqual('gu-mirror');
189+
expect(stubCloned.mock.calls[0][0].className).toBe('gu-mirror');
190190
expect(stubCloned.mock.calls[0][0].innerHTML).toEqual(item.innerHTML);
191191
expect(stubCloned.mock.calls[0][1]).toEqual(item);
192192
});
@@ -220,11 +220,11 @@ describe('drag', () => {
220220
events.raise(item, 'pointerdown', { which: 1 });
221221
events.raise(item, 'pointermove', { which: 1 });
222222

223-
expect(item.className).toEqual('gu-transit');
223+
expect(item.className).toBe('gu-transit');
224224

225225
drake.end();
226226

227-
expect(item.className).toEqual('');
227+
expect(item.className).toBe('');
228228
});
229229

230230
it.skip('when dragging stops, body becomes selectable again', () => {
@@ -237,11 +237,11 @@ describe('drag', () => {
237237
events.raise(item, 'pointerdown', { which: 1 });
238238
events.raise(item, 'pointermove', { which: 1 });
239239

240-
expect(document.body.className).toEqual('gu-unselectable');
240+
expect(document.body.className).toBe('gu-unselectable');
241241

242242
drake.end();
243243

244-
expect(document.body.className).toEqual('');
244+
expect(document.body.className).toBe('');
245245
});
246246

247247
it.skip('when drag begins, check for copy option', () => {
@@ -261,8 +261,8 @@ describe('drag', () => {
261261
events.raise(item, 'pointermove', { which: 1 }); // ensure the copy method condition is only asserted once
262262

263263
expect(stubCopy).toHaveBeenCalledTimes(1);
264-
expect(stubCopy.mock.calls[0][0].className).toEqual('copyable');
265-
expect(stubCopy.mock.calls[0][1].className).toEqual('contains');
264+
expect(stubCopy.mock.calls[0][0].className).toBe('copyable');
265+
expect(stubCopy.mock.calls[0][1].className).toBe('contains');
266266

267267
drake.end();
268268
});

__tests__/drake-api.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ describe('drake-api', () => {
1212
const drake = dragula();
1313

1414
expect(drake).toBeTruthy();
15-
expect(typeof drake).toEqual('object');
15+
expect(typeof drake).toBe('object');
1616
expect(Array.isArray(drake.containers)).toBeTruthy();
17-
expect(typeof drake.start).toEqual('function');
18-
expect(typeof drake.end).toEqual('function');
19-
expect(typeof drake.cancel).toEqual('function');
20-
expect(typeof drake.remove).toEqual('function');
21-
expect(typeof drake.destroy).toEqual('function');
22-
expect(typeof drake.dragging).toEqual('boolean');
17+
expect(typeof drake.start).toBe('function');
18+
expect(typeof drake.end).toBe('function');
19+
expect(typeof drake.cancel).toBe('function');
20+
expect(typeof drake.remove).toBe('function');
21+
expect(typeof drake.destroy).toBe('function');
22+
expect(typeof drake.dragging).toBe('boolean');
2323
expect(drake.dragging).toBeFalsy();
2424
});
2525
});

0 commit comments

Comments
 (0)