Skip to content

Commit

Permalink
Fixed karma conf;
Browse files Browse the repository at this point in the history
getset tests
  • Loading branch information
xobotyi committed Oct 15, 2018
1 parent 2787b4a commit 4ab72de
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 2 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (widthCoverage) {

module.exports = function karmaConfig(config) {
config.set({
browsers: ['Chrome'],
browsers: ['ChromeHeadless'],
singleRun: true,
frameworks: ['mocha'],
files: ['./test.js'],
Expand Down
132 changes: 132 additions & 0 deletions tests/Scrollbar/getset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import expect from "expect";
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import Scrollbar from "react-scrollbars-custom";

export default function performTests() {
describe("getset", () => {
let node;
beforeEach(() => {
node = document.createElement("div");
document.body.appendChild(node);
});
afterEach(() => {
unmountComponentAtNode(node);
document.body.removeChild(node);
});

let sbRender = (cb) => render(<Scrollbar style={ {width: 100, height: 100} }>
<div style={ {width: 200, height: 200} }/>
</Scrollbar>,
node,
cb);

describe("getters", function () {
it("should return scrollTop",
(done) => sbRender(function () {
this.scrollTop = 50;
expect(this.scrollTop).toBe(50);
expect(this.content.scrollTop).toBe(50);

done();
}));

it("should return scrollLeft",
(done) => sbRender(function () {
this.scrollLeft = 50;
expect(this.scrollLeft).toBe(50);
expect(this.content.scrollLeft).toBe(50);

done();
}));

it("should return scrollHeight",
(done) => sbRender(function () {
expect(this.scrollHeight).toBe(200);
expect(this.content.scrollHeight).toBe(200);

done();
}));

it("should return scrollWidth",
(done) => sbRender(function () {
expect(this.scrollWidth).toBe(200);
expect(this.content.scrollWidth).toBe(200);

done();
}));

it("should return clientHeight",
(done) => sbRender(function () {
expect(this.clientHeight).toBe(100);
expect(this.content.clientHeight).toBe(100);

done();
}));

it("should return clientWidth",
(done) => sbRender(function () {
expect(this.clientWidth).toBe(100);
expect(this.content.clientWidth).toBe(100);

done();
}));
});

describe("setters", function () {
it("scrollTop/scrollToTop/scrollToBottom",
(done) => sbRender(function () {
this.scrollTop = 50;
expect(this.scrollTop).toBe(50);
expect(this.content.scrollTop).toBe(50);
this.scrollToTop();
expect(this.content.scrollTop).toBe(0);
this.scrollToBottom();
expect(this.content.scrollTop).toBe(this.content.scrollHeight - this.content.clientHeight);

done();
}));

it("scrollLeft/scrollToLeft/scrollToRight",
(done) => sbRender(function () {
this.scrollLeft = 50;
expect(this.scrollLeft).toBe(50);
expect(this.content.scrollLeft).toBe(50);
this.scrollToLeft();
expect(this.content.scrollLeft).toBe(0);
this.scrollToRight();
expect(this.content.scrollLeft).toBe(this.content.scrollWidth - this.content.clientWidth);

done();
}));

it("scrollHeight should not be settable",
(done) => sbRender(function () {
expect(() => {this.scrollHeight = 0;}).toThrow(TypeError);

done();
}));

it("scrollWidth should not be settable",
(done) => sbRender(function () {
expect(() => {this.scrollWidth = 0;}).toThrow(TypeError);

done();
}));

it("clientHeight should not be settable",
(done) => sbRender(function () {
expect(() => {this.clientHeight = 0;}).toThrow(TypeError);

done();
}));

it("clientWidth should not be settable",
(done) => sbRender(function () {
expect(() => {this.clientWidth = 0;}).toThrow(TypeError);

done();
}));
});
});
}
4 changes: 3 additions & 1 deletion tests/Scrollbar/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import dragging from "./dragging";
import getset from "./getset";
import rendering from "./rendering";

export default function performTests() {
//rendering();
rendering();
dragging();
getset();
}

0 comments on commit 4ab72de

Please sign in to comment.