Skip to content

Commit

Permalink
Add basic tests (ref #81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Denat committed Mar 12, 2018
1 parent 8a10eeb commit eb37f1f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"env": {
"browser": true,
"node": true,
"es6": true
"es6": true,
"jest": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
14 changes: 14 additions & 0 deletions jest/cssTransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

// This is a custom Jest transformer turning style imports into empty objects.
// http://facebook.github.io/jest/docs/en/webpack.html

module.exports = {
process() {
return 'module.exports = {};';
},
getCacheKey() {
// The output is always the same.
return 'cssTransform';
},
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
],
"moduleFileExtensions": [
"js"
]
],
"moduleNameMapper": {
"\\.(css)$": "<rootDir>/jest/cssTransform.js"
}
}
}
26 changes: 25 additions & 1 deletion src/simplebar.test.js
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
import SimpleBar from './simplebar';
import SimpleBar from './simplebar';

beforeEach(() => {
jest.resetModules();

// Set up our document body
document.body.innerHTML = '<div id="simplebar"></div>';
});

test('should call constructor', () => {
const SimpleBar = require('./simplebar').default;
jest.mock('./simplebar');

const simpleBar = new SimpleBar(document.getElementById('simplebar'));

expect(SimpleBar).toHaveBeenCalledTimes(1);
});
test('should return right scroll element', () => {
const simpleBar = new SimpleBar(document.getElementById('simplebar'));
const scrollElementY = simpleBar.getScrollElement();
const scrollElementX = simpleBar.getScrollElement('x');

expect(scrollElementY).toBe(simpleBar.scrollContentEl);
expect(scrollElementX).toBe(simpleBar.contentEl);
});

0 comments on commit eb37f1f

Please sign in to comment.