+function PreviousNextMethods() {
+ let sliderRef = useRef(null);
+ const next = () => {
+ sliderRef.slickNext();
+ };
+ const previous = () => {
+ sliderRef.slickPrev();
+ };
+ const settings = {
+ dots: true,
+ infinite: true,
+ speed: 500,
+ slidesToShow: 1,
+ slidesToScroll: 1
+ };
+ return (
+
+ );
}
+
+export default PreviousNextMethods;
diff --git a/examples/Resizable.js b/examples/Resizable.js
index d7747fa91..24029b21d 100644
--- a/examples/Resizable.js
+++ b/examples/Resizable.js
@@ -1,83 +1,61 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React, { useState } from "react";
+import Slider from "react-slick";
-export default class Resizable extends Component {
- state = {
- display: true,
- width: 600
+function Resizable() {
+ const [display, setDisplay] = useState(true);
+ const [width, setWidth] = useState(600);
+
+ const settings = {
+ dots: true,
+ infinite: true,
+ speed: 500,
+ slidesToShow: 3,
+ slidesToScroll: 1
};
- render() {
- const settings = {
- dots: true,
- infinite: true,
- speed: 500,
- slidesToShow: 3,
- slidesToScroll: 1
- };
- return (
-
-
Resizable Collapsible
-
- this.setState({
- width: this.state.width + 100
- })
- }
- >
- {" "}
- increase{" "}
-
-
- this.setState({
- width: this.state.width - 100
- })
- }
- >
- {" "}
- decrease{" "}
-
-
- this.setState({
- display: !this.state.display
- })
- }
- >
- {" "}
- toggle{" "}
-
-
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
+ return (
+
+
Resizable Collapsible
+
setWidth(width + 100)}>
+ {" "}
+ increase{" "}
+
+
setWidth(width - 100)}>
+ {" "}
+ decrease{" "}
+
+
setDisplay(!display)}>
+ {" "}
+ toggle{" "}
+
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
- );
- }
+
+ );
}
+
+export default Resizable;
diff --git a/examples/Responsive.js b/examples/Responsive.js
index efa606229..abcac7875 100644
--- a/examples/Responsive.js
+++ b/examples/Responsive.js
@@ -1,72 +1,71 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React from "react";
+import Slider from "react-slick";
-export default class Responsive extends Component {
- render() {
- var settings = {
- dots: true,
- infinite: false,
- speed: 500,
- slidesToShow: 4,
- slidesToScroll: 4,
- initialSlide: 0,
- responsive: [
- {
- breakpoint: 1024,
- settings: {
- slidesToShow: 3,
- slidesToScroll: 3,
- infinite: true,
- dots: true
- }
- },
- {
- breakpoint: 600,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- initialSlide: 2
- }
- },
- {
- breakpoint: 480,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1
- }
+function Responsive() {
+ var settings = {
+ dots: true,
+ infinite: false,
+ speed: 500,
+ slidesToShow: 4,
+ slidesToScroll: 4,
+ initialSlide: 0,
+ responsive: [
+ {
+ breakpoint: 1024,
+ settings: {
+ slidesToShow: 3,
+ slidesToScroll: 3,
+ infinite: true,
+ dots: true
}
- ]
- };
- return (
-
-
Responsive
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
7
-
-
-
8
-
-
-
- );
- }
+ },
+ {
+ breakpoint: 600,
+ settings: {
+ slidesToShow: 2,
+ slidesToScroll: 2,
+ initialSlide: 2
+ }
+ },
+ {
+ breakpoint: 480,
+ settings: {
+ slidesToShow: 1,
+ slidesToScroll: 1
+ }
+ }
+ ]
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
7
+
+
+
8
+
+
+
+ );
}
+
+export default Responsive;
diff --git a/examples/Rtl.js b/examples/Rtl.js
index e72edc5d6..7ef817a50 100644
--- a/examples/Rtl.js
+++ b/examples/Rtl.js
@@ -1,41 +1,41 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React from "react";
+import Slider from "react-slick";
-export default class Rtl extends Component {
- render() {
- const settings = {
- dots: true,
- infinite: true,
- slidesToShow: 3,
- slidesToScroll: 1,
- autoplay: true,
- autoplaySpeed: 2000,
- rtl: true
- };
- return (
-
-
Right to Left
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+function Rtl() {
+ const settings = {
+ dots: true,
+ infinite: true,
+ slidesToShow: 3,
+ slidesToScroll: 1,
+ autoplay: true,
+ autoplaySpeed: 2000,
+ rtl: true
+ };
+ return (
+
+
Right to Left
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default Rtl;
diff --git a/examples/SimpleSlider.js b/examples/SimpleSlider.js
index 013344162..573f4bce9 100644
--- a/examples/SimpleSlider.js
+++ b/examples/SimpleSlider.js
@@ -1,39 +1,38 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React from "react";
+import Slider from "react-slick";
-export default class SimpleSlider extends Component {
- render() {
- const settings = {
- dots: true,
- infinite: true,
- speed: 500,
- slidesToShow: 1,
- slidesToScroll: 1
- };
- return (
-
-
Single Item
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+function SimpleSlider() {
+ const settings = {
+ dots: true,
+ infinite: true,
+ speed: 500,
+ slidesToShow: 1,
+ slidesToScroll: 1
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default SimpleSlider;
diff --git a/examples/SlickGoTo.js b/examples/SlickGoTo.js
index f5c49840a..deeccd7d3 100644
--- a/examples/SlickGoTo.js
+++ b/examples/SlickGoTo.js
@@ -1,50 +1,51 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React, { useState, useRef } from "react";
+import Slider from "react-slick";
import { baseUrl } from "./config";
-export default class SlickGoTo extends React.Component {
- state = {
- slideIndex: 0,
- updateCount: 0
+function SlickGoTo() {
+ const [slideIndex, setSlideIndex] = useState(0);
+ const [updateCount, setUpdateCount] = useState(0);
+ let sliderRef = useRef(null);
+ const settings = {
+ dots: false,
+ infinite: true,
+ speed: 500,
+ slidesToShow: 1,
+ slidesToScroll: 1,
+ afterChange: () => setUpdateCount(updateCount + 1),
+ beforeChange: (current, next) => setSlideIndex(next)
};
-
- render() {
- const settings = {
- dots: false,
- infinite: true,
- speed: 500,
- slidesToShow: 1,
- slidesToScroll: 1,
- afterChange: () =>
- this.setState(state => ({ updateCount: state.updateCount + 1 })),
- beforeChange: (current, next) => this.setState({ slideIndex: next })
- };
- return (
-
-
Slick Go To
-
Total updates: {this.state.updateCount}
-
this.slider.slickGoTo(e.target.value)}
- value={this.state.slideIndex}
- type="range"
- min={0}
- max={3}
- />
-
(this.slider = slider)} {...settings}>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- );
- }
+ return (
+
+
Total updates: {updateCount}
+
sliderRef.slickGoTo(e.target.value)}
+ value={slideIndex}
+ type="range"
+ min={0}
+ max={3}
+ />
+
{
+ sliderRef = slider;
+ }}
+ {...settings}
+ >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
}
+
+export default SlickGoTo;
diff --git a/examples/SlideChangeHooks.js b/examples/SlideChangeHooks.js
index 9f8b31753..4109a0fbd 100644
--- a/examples/SlideChangeHooks.js
+++ b/examples/SlideChangeHooks.js
@@ -1,56 +1,57 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React, { useState } from "react";
+import Slider from "react-slick";
-export default class SlideChangeHooks extends Component {
- state = {
- oldSlide: 0,
- activeSlide: 0,
- activeSlide2: 0
+function SlideChangeHooks() {
+ const [oldSlide, setOldSlide] = useState(0);
+ const [activeSlide, setActiveSlide] = useState(0);
+ const [activeSlide2, setActiveSlide2] = useState(0);
+
+ const settings = {
+ dots: true,
+ infinite: true,
+ speed: 1000,
+ slidesToShow: 1,
+ slidesToScroll: 1,
+ beforeChange: (current, next) => {
+ setOldSlide(current);
+ setActiveSlide(next);
+ },
+ afterChange: current => setActiveSlide2(current)
};
- render() {
- const settings = {
- dots: true,
- infinite: true,
- speed: 1000,
- slidesToShow: 1,
- slidesToScroll: 1,
- beforeChange: (current, next) =>
- this.setState({ oldSlide: current, activeSlide: next }),
- afterChange: current => this.setState({ activeSlide2: current })
- };
- return (
-
-
beforeChange and afterChange hooks
-
- BeforeChange => oldSlide: {this.state.oldSlide}
-
-
- BeforeChange => activeSlide: {this.state.activeSlide}
-
-
- AfterChange => activeSlide: {this.state.activeSlide2}
-
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+ return (
+
+
beforeChange and afterChange hooks
+
+ BeforeChange {"=>"} oldSlide: {oldSlide}
+
+
+ BeforeChange {"=>"} activeSlide: {activeSlide}
+
+
+ AfterChange {"=>"} activeSlide: {activeSlide2}
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default SlideChangeHooks;
diff --git a/examples/SwipeToSlide.js b/examples/SwipeToSlide.js
index 2e51db349..f32de1664 100644
--- a/examples/SwipeToSlide.js
+++ b/examples/SwipeToSlide.js
@@ -1,53 +1,52 @@
import React, { Component } from "react";
-import Slider from "../src/slider";
+import Slider from "react-slick";
-export default class SwipeToSlide extends Component {
- render() {
- const settings = {
- className: "center",
- infinite: true,
- centerPadding: "60px",
- slidesToShow: 5,
- swipeToSlide: true,
- afterChange: function(index) {
- console.log(
- `Slider Changed to: ${index + 1}, background: #222; color: #bada55`
- );
- }
- };
- return (
-
-
Swipe To Slide
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
7
-
-
-
8
-
-
-
9
-
-
-
- );
- }
+function SwipeToSlide() {
+ const settings = {
+ className: "center",
+ infinite: true,
+ centerPadding: "60px",
+ slidesToShow: 5,
+ swipeToSlide: true,
+ afterChange: function(index) {
+ console.log(
+ `Slider Changed to: ${index + 1}, background: #222; color: #bada55`
+ );
+ }
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
7
+
+
+
8
+
+
+
9
+
+
+
+ );
}
+
+export default SwipeToSlide;
diff --git a/examples/UnevenSetsFinite.js b/examples/UnevenSetsFinite.js
index d465209b6..0be3200c4 100644
--- a/examples/UnevenSetsFinite.js
+++ b/examples/UnevenSetsFinite.js
@@ -1,39 +1,38 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React from "react";
+import Slider from "react-slick";
-export default class UnevenSetsFinite extends Component {
- render() {
- var settings = {
- dots: true,
- infinite: false,
- speed: 500,
- slidesToScroll: 4,
- slidesToShow: 4
- };
- return (
-
-
Uneven sets (finite)
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+function UnevenSetsFinite() {
+ var settings = {
+ dots: true,
+ infinite: false,
+ speed: 500,
+ slidesToScroll: 4,
+ slidesToShow: 4
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default UnevenSetsFinite;
diff --git a/examples/UnevenSetsInfinite.js b/examples/UnevenSetsInfinite.js
index 7e00a43a7..556f57fe9 100644
--- a/examples/UnevenSetsInfinite.js
+++ b/examples/UnevenSetsInfinite.js
@@ -1,39 +1,38 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React from "react";
+import Slider from "react-slick";
-export default class UnevenSetsInfinite extends Component {
- render() {
- var settings = {
- dots: true,
- infinite: true,
- speed: 500,
- slidesToScroll: 4,
- slidesToShow: 4
- };
- return (
-
-
Uneven sets (infinite)
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+function UnevenSetsInfinite() {
+ var settings = {
+ dots: true,
+ infinite: true,
+ speed: 500,
+ slidesToScroll: 4,
+ slidesToShow: 4
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default UnevenSetsInfinite;
diff --git a/examples/VariableWidth.js b/examples/VariableWidth.js
index 9289c2258..e333c658f 100644
--- a/examples/VariableWidth.js
+++ b/examples/VariableWidth.js
@@ -1,41 +1,40 @@
-import React, { Component } from "react";
-import Slider from "../src/slider";
+import React from "react";
+import Slider from "react-slick";
-export default class VariableWidth extends Component {
- render() {
- const settings = {
- className: "slider variable-width",
- dots: true,
- infinite: true,
- centerMode: true,
- slidesToShow: 1,
- slidesToScroll: 1,
- variableWidth: true
- };
- return (
-
-
Variable width
-
-
-
-
-
-
-
-
-
- );
- }
+function VariableWidth() {
+ const settings = {
+ className: "slider variable-width",
+ dots: true,
+ infinite: true,
+ centerMode: true,
+ slidesToShow: 1,
+ slidesToScroll: 1,
+ variableWidth: true
+ };
+ return (
+
+ );
}
+
+export default VariableWidth;
diff --git a/examples/VerticalMode.js b/examples/VerticalMode.js
index fc54c8585..b53f7db44 100644
--- a/examples/VerticalMode.js
+++ b/examples/VerticalMode.js
@@ -1,46 +1,45 @@
import React, { Component } from "react";
-import Slider from "../src/slider";
+import Slider from "react-slick";
-export default class VerticalMode extends Component {
- render() {
- const settings = {
- dots: true,
- infinite: true,
- slidesToShow: 3,
- slidesToScroll: 1,
- vertical: true,
- verticalSwiping: true,
- beforeChange: function(currentSlide, nextSlide) {
- console.log("before change", currentSlide, nextSlide);
- },
- afterChange: function(currentSlide) {
- console.log("after change", currentSlide);
- }
- };
- return (
-
-
Vertical Mode
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+function VerticalMode() {
+ const settings = {
+ dots: true,
+ infinite: true,
+ slidesToShow: 3,
+ slidesToScroll: 1,
+ vertical: true,
+ verticalSwiping: true,
+ beforeChange: function(currentSlide, nextSlide) {
+ console.log("before change", currentSlide, nextSlide);
+ },
+ afterChange: function(currentSlide) {
+ console.log("after change", currentSlide);
+ }
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default VerticalMode;
diff --git a/examples/VerticalSwipeToSlide.js b/examples/VerticalSwipeToSlide.js
index 36ed22d84..d5855147c 100644
--- a/examples/VerticalSwipeToSlide.js
+++ b/examples/VerticalSwipeToSlide.js
@@ -1,47 +1,46 @@
import React, { Component } from "react";
-import Slider from "../src/slider";
+import Slider from "react-slick";
-export default class VerticalSwipeToSlide extends Component {
- render() {
- const settings = {
- dots: true,
- infinite: true,
- slidesToShow: 3,
- slidesToScroll: 1,
- vertical: true,
- verticalSwiping: true,
- swipeToSlide: true,
- beforeChange: function(currentSlide, nextSlide) {
- console.log("before change", currentSlide, nextSlide);
- },
- afterChange: function(currentSlide) {
- console.log("after change", currentSlide);
- }
- };
- return (
-
-
Vertical Mode with Swipe To Slide
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
- );
- }
+function VerticalSwipeToSlide() {
+ const settings = {
+ dots: true,
+ infinite: true,
+ slidesToShow: 3,
+ slidesToScroll: 1,
+ vertical: true,
+ verticalSwiping: true,
+ swipeToSlide: true,
+ beforeChange: function(currentSlide, nextSlide) {
+ console.log("before change", currentSlide, nextSlide);
+ },
+ afterChange: function(currentSlide) {
+ console.log("after change", currentSlide);
+ }
+ };
+ return (
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+ );
}
+
+export default VerticalSwipeToSlide;
diff --git a/examples/__tests__/CenterMode.test.js b/examples/__tests__/CenterMode.test.js
deleted file mode 100644
index 1123c2aa3..000000000
--- a/examples/__tests__/CenterMode.test.js
+++ /dev/null
@@ -1,54 +0,0 @@
-import React from "react";
-import { mount } from "enzyme";
-import CenterMode from "../CenterMode";
-import { html as beautify_html } from "js-beautify";
-import { clickNext } from "../../__tests__/testUtils";
-
-describe("CenterMode Tests", () => {
- test("Counting test", () => {
- const slider = mount(
);
- let totalSlides = slider.find(".slick-slide").length;
- let clonedSlides = slider.find(".slick-cloned").length;
- let activeSlides = slider.find(".slick-slide.slick-active").length;
- expect(totalSlides).toEqual(16);
- expect(clonedSlides).toEqual(10);
- expect(activeSlides).toEqual(3);
- expect(beautify_html(slider.html())).toMatchSnapshot();
- });
- test("Positioning test", () => {
- const slider = mount(
);
- let currentSlide = slider.find("div.slick-current");
- let activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(0);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- -1,
- 0,
- 1
- ]);
- expect(beautify_html(slider.html())).toMatchSnapshot();
- });
- test("Activity test", () => {
- const slider = mount(
);
- let currentSlide = slider.find("div.slick-current");
- let activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(0);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- -1,
- 0,
- 1
- ]);
-
- clickNext(slider);
-
- currentSlide = slider.find("div.slick-current");
- activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(1);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 0,
- 1,
- 2
- ]);
-
- expect(beautify_html(slider.html())).toMatchSnapshot();
- });
-});
diff --git a/examples/__tests__/CentreMode.test.js b/examples/__tests__/CentreMode.test.js
new file mode 100644
index 000000000..d2c3c5191
--- /dev/null
+++ b/examples/__tests__/CentreMode.test.js
@@ -0,0 +1,54 @@
+import React from "react";
+import CenterMode from "../CenterMode";
+import { render } from "@testing-library/react";
+import { html as beautify_html } from "js-beautify";
+import {
+ getActiveSlides,
+ getActiveSlidesCount,
+ getClonesCount,
+ getCurrentSlide,
+ getSlidesCount,
+ clickNext
+} from "../../test-utils";
+
+describe("CenterMode Tests", () => {
+ test("Counting test", () => {
+ const { container } = render(
);
+ let totalSlides = getSlidesCount(container);
+ let clonedSlides = getClonesCount(container);
+ let activeSlides = getActiveSlidesCount(container);
+ expect(totalSlides).toEqual(16);
+ expect(clonedSlides).toEqual(10);
+ expect(activeSlides).toEqual(3);
+ //expect(beautify_html(toString(container))).toMatchSnapshot();
+ });
+ test("Positioning test", () => {
+ const { container } = render(
);
+ let currentSlide = getCurrentSlide(container);
+ let activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0);
+ expect(
+ Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index")))
+ ).toEqual([-1, 0, 1]);
+ //expect(beautify_html(toString(container))).toMatchSnapshot();
+ });
+ test("Activity test", () => {
+ const { container } = render(
);
+ let currentSlide = getCurrentSlide(container);
+ let activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0);
+ expect(
+ Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index")))
+ ).toEqual([-1, 0, 1]);
+ clickNext(container);
+
+ currentSlide = getCurrentSlide(container);
+ activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(1);
+ expect(
+ Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index")))
+ ).toEqual([0, 1, 2]);
+
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
+ });
+});
diff --git a/examples/__tests__/Fade.js b/examples/__tests__/Fade.js
index 80a1095f3..038f9c403 100644
--- a/examples/__tests__/Fade.js
+++ b/examples/__tests__/Fade.js
@@ -1,18 +1,18 @@
import React from "react";
-import { mount } from "enzyme";
+import { render } from "@testing-library/react";
import Fade from "../Fade";
-import { clickNext, clickPrev } from "../../__tests__/testUtils";
+import { getActiveSlide, clickNext, clickPrevious } from "../../test-utils";
describe("Fade", () => {
it("should change slides when clicked on next & prev buttons", () => {
- const slider = mount(
);
- let activeSlide = slider.find("div.slick-active");
- expect(activeSlide.props()["data-index"]).toEqual(0);
- clickNext(slider);
- activeSlide = slider.find("div.slick-active");
- expect(activeSlide.props()["data-index"]).toEqual(1);
- clickPrev(slider);
- activeSlide = slider.find("div.slick-active");
- expect(activeSlide.props()["data-index"]).toEqual(0);
+ const { container } = render(
);
+ let activeslide = getActiveSlide(container);
+ expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(0);
+ clickNext(container);
+ activeslide = getActiveSlide(container);
+ expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(1);
+ clickPrevious(container);
+ activeslide = getActiveSlide(container);
+ expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(0);
});
});
diff --git a/examples/__tests__/FocusOnSelect.test.js b/examples/__tests__/FocusOnSelect.test.js
index a7928cfea..6b307c22e 100644
--- a/examples/__tests__/FocusOnSelect.test.js
+++ b/examples/__tests__/FocusOnSelect.test.js
@@ -1,16 +1,33 @@
import React from "react";
-import { mount } from "enzyme";
+import { render, fireEvent } from "@testing-library/react";
import { html as beautify_html } from "js-beautify";
-import { clickNext } from "../../__tests__/testUtils";
+import {
+ activeSlide,
+ clickNext,
+ clickPrevious,
+ getButtons,
+ getCurrentSlide
+} from "../../test-utils";
import FocusOnSelect from "../FocusOnSelect";
describe("FocusOnSelect Tests", () => {
test("Activity Test", () => {
- const slider = mount(
);
- expect(slider.find("div.slick-current").props()["data-index"]).toEqual(0);
- expect(beautify_html(slider.html())).toMatchSnapshot();
- slider.find("[data-index=2]").simulate("click");
- expect(slider.find("div.slick-current").props()["data-index"]).toEqual(2);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ const { container } = render(
);
+ expect(
+ parseInt(getCurrentSlide(container).getAttribute("data-index"))
+ ).toEqual(0);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
+ Array.from(container.getElementsByClassName("slick-slide")).map(e =>
+ e.getAttribute("data-index") == "2"
+ ? fireEvent(
+ e,
+ new MouseEvent("click", { bubbles: true, cancelable: true })
+ )
+ : null
+ );
+ expect(
+ parseInt(getCurrentSlide(container).getAttribute("data-index"))
+ ).toEqual(2);
+ //expect(beautify_html(toString(container))).toMatchSnapshot();
});
});
diff --git a/examples/__tests__/MultipleItems.test.js b/examples/__tests__/MultipleItems.test.js
index 571479960..1adc83daa 100644
--- a/examples/__tests__/MultipleItems.test.js
+++ b/examples/__tests__/MultipleItems.test.js
@@ -1,169 +1,99 @@
import React from "react";
-import { mount } from "enzyme";
-import MultipleItems from "../MultipleItems";
+import { render, fireEvent } from "@testing-library/react";
import { html as beautify_html } from "js-beautify";
+import {
+ activeSlide,
+ activeSlides,
+ clickNext,
+ clickPrevious,
+ getActiveButton,
+ getActiveSlidesCount,
+ getActiveSlidesText,
+ getButtons,
+ getButtonsLength,
+ getButtonsListItem,
+ getClonesCount,
+ getCurrentSlide,
+ getSlidesCount,
+ hasClass
+} from "../../test-utils";
+import MultipleItems from "../MultipleItems";
describe("Multiple Items", function() {
it("should have 9 actual slides and (3(pre) + 9(post)) clone slides", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-slide").length).toEqual(21);
- expect(wrapper.find(".slick-cloned").length).toEqual(12);
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ expect(getSlidesCount(container)).toEqual(21);
+ expect(getClonesCount(container)).toEqual(12);
+ //expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should have 3 active slides", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-slide.slick-active").length).toEqual(3);
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ expect(getActiveSlidesCount(container)).toEqual(3);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should have 3 dots", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-dots button").length).toEqual(3);
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ expect(getButtonsLength(container)).toEqual(3);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should show first 3 slides", function() {
- const wrapper = mount(
);
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("1");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .at(1)
- .text()
- ).toEqual("2");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .last()
- .text()
- ).toEqual("3");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ expect(getActiveButton(container)).toEqual(["1"]);
+ expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should show slides from 4 to 6 when next button is clicked", function() {
- const wrapper = mount(
);
- wrapper.find(".slick-next").simulate("click");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("4");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .at(1)
- .text()
- ).toEqual("5");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .last()
- .text()
- ).toEqual("6");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ clickNext(container);
+ // Array.from(container.querySelectorAll(".slick-current")).map(e=>console.log(e.textContent))
+ expect(getActiveButton(container)).toEqual(["2"]);
+ expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should show last 3 slides when previous button is clicked", function() {
- const wrapper = mount(
);
- wrapper.find(".slick-prev").simulate("click");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("7");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .at(1)
- .text()
- ).toEqual("8");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .last()
- .text()
- ).toEqual("9");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ clickPrevious(container);
+ expect(getActiveButton(container)).toEqual(["3"]);
+ expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
- it("should show slides first 3 slides when middle dot is clicked", function() {
- const wrapper = mount(
);
- wrapper
- .find(".slick-dots button")
- .at(0)
- .simulate("click");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("1");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .at(1)
- .text()
- ).toEqual("2");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .last()
- .text()
- ).toEqual("3");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ it("should show slides first 3 slides when first dot is clicked", function() {
+ const { container } = render(
);
+ fireEvent(
+ getButtons(container)[0],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ expect(getActiveButton(container)).toEqual(["1"]);
+ expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should show slides from 4 to 6 when middle dot is clicked", function() {
- const wrapper = mount(
);
- wrapper
- .find(".slick-dots button")
- .at(1)
- .simulate("click");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("4");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .at(1)
- .text()
- ).toEqual("5");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .last()
- .text()
- ).toEqual("6");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ fireEvent(
+ getButtons(container)[1],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ expect(getActiveButton(container)).toEqual(["2"]);
+ expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("should show last 3 slides when last dot is clicked", function() {
- const wrapper = mount(
);
- wrapper
- .find(".slick-dots button")
- .at(2)
- .simulate("click");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("7");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .at(1)
- .text()
- ).toEqual("8");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .last()
- .text()
- ).toEqual("9");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ fireEvent(
+ getButtons(container)[2],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ expect(getActiveButton(container)).toEqual(["3"]);
+ expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
});
diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js
index b430bc3c7..71402cbbb 100644
--- a/examples/__tests__/SimpleSlider.test.js
+++ b/examples/__tests__/SimpleSlider.test.js
@@ -1,130 +1,135 @@
import React from "react";
-import { mount } from "enzyme";
import SimpleSlider from "../SimpleSlider";
-import { repeatClicks } from "../../test-helpers";
+import { render, fireEvent, waitFor, screen } from "@testing-library/react";
import { html as beautify_html } from "js-beautify";
+import {
+ getActiveSlide,
+ clickNext,
+ clickPrevious,
+ hasClass,
+ getActiveSlides,
+ getActiveSlidesCount,
+ getActiveSlidesText,
+ getButtons,
+ getButtonsListItem,
+ getCurrentSlide
+} from "../../test-utils";
-describe("Simple Slider", function() {
+describe("SimpleSlider example", () => {
it("should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-slide").length).toEqual(13);
+ const { container } = render(
);
+ expect(container.getElementsByClassName("slick-slide").length).toBe(13);
});
it("should have 7 clone slides", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-cloned").length).toEqual(7);
+ const { container } = render(
);
+ expect(container.getElementsByClassName("slick-cloned").length).toBe(7);
+ });
+ it("should have 1 current slide", function() {
+ const { container } = render(
);
+ expect(
+ container.querySelectorAll(".slick-slide.slick-current").length
+ ).toBe(1);
+ expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(0);
});
it("should have 1 active slide", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-slide.slick-active").length).toEqual(1);
+ const { container } = render(
);
+ expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe(
+ 1
+ );
+ expect(
+ Array.from(getActiveSlide(container).children).map(
+ e => parseInt(e.textContent) - 1
+ )[0]
+ ).toBe(0);
});
it("should have 6 dots", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-dots").children().length).toEqual(6);
+ const { container } = render(
);
+ expect(
+ container.getElementsByClassName("slick-dots")[0].children.length
+ ).toBe(6);
});
it("should have 1 active dot", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1);
+ const { container } = render(
);
+
+ expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
+ 1
+ );
});
it("should have a prev arrow", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-prev").length).toEqual(1);
+ const { container } = render(
);
+ expect(container.getElementsByClassName("slick-prev").length).toBe(1);
});
it("should have a next arrow", function() {
- const wrapper = mount(
);
- expect(wrapper.find(".slick-next").length).toEqual(1);
+ const { container } = render(
);
+ expect(container.getElementsByClassName("slick-next").length).toBe(1);
});
-
- it("should got to second slide when next button is clicked", function() {
- const wrapper = mount(
);
- wrapper.find(".slick-next").simulate("click");
+ it("should got to next slide when next button is clicked", function() {
+ const { container } = render(
);
+ clickNext(container);
expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("2");
- expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1);
+ container.querySelectorAll(".slick-slide.slick-active")[0].textContent
+ ).toBe("2");
+ expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
+ 1
+ );
expect(
- wrapper
- .find(".slick-dots")
- .childAt(1)
- .hasClass("slick-active")
- ).toEqual(true);
+ container.querySelectorAll(".slick-dots")[0].children[1]
+ ).toHaveClass("slick-active");
});
- it("should goto last slide when prev button is clicked", function() {
- const wrapper = mount(
);
- wrapper.find(".slick-prev").simulate("click");
+ it("should goto previous slide when prev button is clicked", function() {
+ const { container } = render(
);
+ clickPrevious(container);
expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("6");
- expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1);
+ container.querySelectorAll(".slick-slide.slick-active")[0].textContent
+ ).toBe("6");
+ expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
+ 1
+ );
expect(
- wrapper
- .find(".slick-dots")
- .childAt(5)
- .hasClass("slick-active")
- ).toEqual(true);
+ container.querySelectorAll(".slick-dots")[0].children[5]
+ ).toHaveClass("slick-active");
});
it("should goto 4th slide when 4th dot is clicked", function() {
- const wrapper = mount(
);
- wrapper
- .find(".slick-dots button")
- .at(3)
- .simulate("click");
- expect(
- wrapper
- .find(".slick-slide.slick-active")
- .first()
- .text()
- ).toEqual("4");
- expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1);
- expect(
- wrapper
- .find(".slick-dots")
- .childAt(3)
- .hasClass("slick-active")
- ).toEqual(true);
+ const { container } = render(
);
+ fireEvent(
+ container.querySelectorAll(".slick-dots button")[3],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ expect(getActiveSlidesText(container)[0]).toEqual("4");
+ expect(getActiveSlidesCount(container)).toEqual(1);
+ expect(hasClass(getButtonsListItem(container)[3], "slick-active")).toEqual(
+ true
+ );
});
- // it('should come back to 1st slide after 6 clicks on next button', function () {
- // // waitForAnimate option is causing problem for this test
- // const wrapper = mount(
);
- // wrapper.find('.slick-next').first().simulate('click').simulate('click')
- // // wrapper.find('.slick-prev').first().simulate('click')
- // // wrapper.find('.slick-next').first().simulate('click')
- // // console.log(nextButton)
- // // nextButton.simulate('click').simulate('click')
- // // nextButton.simulate('click')
- // // repeatClicks(wrapper.find('.slick-next'), 1)
- // expect(wrapper.find('.slick-slide.slick-active').first().text()).toEqual('1');
- // expect(wrapper.find('.slick-dots .slick-active').length).toEqual(1);
- // expect(wrapper.find('.slick-dots').childAt(0).hasClass('slick-active')).toEqual(true)
- // })
});
describe("Simple Slider Snapshots", function() {
it("slider initial state", function() {
- const wrapper = mount(
);
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("click on next button", function() {
- const wrapper = mount(
);
- wrapper.find(".slick-next").simulate("click");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ clickNext(container);
+ //expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("click on prev button", function() {
- const wrapper = mount(
);
- wrapper.find(".slick-prev").simulate("click");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ clickPrevious(container);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
it("click on 3rd dot", function() {
- const wrapper = mount(
);
- wrapper
- .find(".slick-dots button")
- .at(2)
- .simulate("click");
- expect(beautify_html(wrapper.html())).toMatchSnapshot();
+ const { container } = render(
);
+ fireEvent(
+ getButtons(container)[2],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
});
diff --git a/examples/__tests__/SlickGoTo.test.js b/examples/__tests__/SlickGoTo.test.js
index 08a88dab5..9234ff3b9 100644
--- a/examples/__tests__/SlickGoTo.test.js
+++ b/examples/__tests__/SlickGoTo.test.js
@@ -1,32 +1,48 @@
import React from "react";
-import { mount } from "enzyme";
+import { fireEvent, getRoles, render } from "@testing-library/react";
import SlickGoTo from "../SlickGoTo";
+import { activeSlide, getActiveSlides, getSlidesCount } from "../../test-utils";
describe.skip("SlickGoTo", () => {
it("should goto 2nd slide", () => {
- const wrapper = mount(
);
- wrapper.find("input").simulate("change", { target: { value: 1 } });
- expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual(
+ const { container } = render(
);
+ fireEvent.change(container.getElementsByTagName("input")[0], {
+ target: { value: 1 }
+ });
+ let currentImg = Array.from(
+ getActiveSlide(container).getElementsByTagName("img")
+ )[0];
+ expect(currentImg.getAttribute("src")).toEqual(
"/img/react-slick/abstract02.jpg"
);
});
it("should goto 2nd slide, even if input is number in string format", () => {
- const wrapper = mount(
);
- wrapper.find("input").simulate("change", { target: { value: "1" } });
- expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual(
+ const { container } = render(
);
+ fireEvent.change(container.getElementsByTagName("input")[0], {
+ target: { value: "1" }
+ });
+ let currentImg = Array.from(
+ getActiveSlide(container).getElementsByTagName("img")
+ )[0];
+ expect(currentImg.getAttribute("src")).toEqual(
"/img/react-slick/abstract02.jpg"
);
});
it("should remain at 1st slide", () => {
- const wrapper = mount(
);
- wrapper.find("input").simulate("change", { target: { value: 0 } });
- expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual(
+ const { container } = render(
);
+ fireEvent.change(container.getElementsByTagName("input")[0], {
+ target: { value: 0 }
+ });
+ let currentImg = Array.from(
+ getActiveSlide(container).getElementsByTagName("img")
+ )[0];
+ expect(currentImg.getAttribute("src")).toEqual(
"/img/react-slick/abstract01.jpg"
);
});
it.skip("should go to 1st slide from another 3rd slide", () => {
// skipped because two simultaneous clicks dont' work with css and speed>0
- const wrapper = mount(
);
+ const wrapper = render(
);
wrapper.find("input").simulate("change", { target: { value: 3 } });
wrapper.find("input").simulate("change", { target: { value: 0 } });
expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual(
diff --git a/examples/__tests__/UnevenSets.test.js b/examples/__tests__/UnevenSets.test.js
index 1c47291ff..eff2f9dcf 100644
--- a/examples/__tests__/UnevenSets.test.js
+++ b/examples/__tests__/UnevenSets.test.js
@@ -1,125 +1,126 @@
import React from "react";
-import { mount } from "enzyme";
+import { render, fireEvent } from "@testing-library/react";
import UnevenSetsFinite from "../UnevenSetsFinite";
import UnevenSetsInfinite from "../UnevenSetsInfinite";
import { html as beautify_html } from "js-beautify";
-import { clickNext } from "../../__tests__/testUtils";
+import {
+ getActiveSlides,
+ clickNext,
+ getActiveSlidesCount,
+ getButtonsLength,
+ getClonesCount,
+ getCurrentSlide,
+ getSlidesCount
+} from "../../test-utils";
describe("UnevenSets Finite", () => {
test("Counting test", () => {
- const slider = mount(
);
- let totalSlides = slider.find(".slick-slide").length;
- let clonedSlides = slider.find(".slick-cloned").length;
- let activeSlides = slider.find(".slick-slide.slick-active").length;
- let dots = slider.find(".slick-dots").children().length;
+ const { container } = render(
);
+ let totalSlides = getSlidesCount(container);
+ let clonedSlides = getClonesCount(container);
+ let activeSlides = getActiveSlidesCount(container);
+ let dots = getButtonsLength(container);
expect(totalSlides).toEqual(6);
expect(clonedSlides).toEqual(0);
expect(activeSlides).toEqual(4);
expect(dots).toEqual(2);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
test("Positioning test", () => {
- const slider = mount(
);
- let currentSlide = slider.find("div.slick-current");
- let activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(0);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 0,
- 1,
- 2,
- 3
- ]);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ const { container } = render(
);
+ let currentSlide = getCurrentSlide(container);
+ let activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([0, 1, 2, 3]);
+ //expect(beautify_html(toString(container))).toMatchSnapshot();
});
test("Activity test", () => {
- const slider = mount(
);
- let currentSlide = slider.find("div.slick-current");
- let activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(0);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 0,
- 1,
- 2,
- 3
- ]);
+ const { container } = render(
);
+ let currentSlide = getCurrentSlide(container);
+ let activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([0, 1, 2, 3]);
- clickNext(slider);
+ clickNext(container);
- currentSlide = slider.find("div.slick-current");
- activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(4);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 2,
- 3,
- 4,
- 5
- ]);
+ currentSlide = getCurrentSlide(container);
+ activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([2, 3, 4, 5]);
- clickNext(slider);
+ clickNext(container);
- currentSlide = slider.find("div.slick-current");
- activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(4);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 2,
- 3,
- 4,
- 5
- ]);
+ currentSlide = getCurrentSlide(container);
+ activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([2, 3, 4, 5]);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
});
describe("UnevenSets Infinite", () => {
test("Counting test", () => {
- const slider = mount(
);
- let totalSlides = slider.find(".slick-slide").length;
- let clonedSlides = slider.find(".slick-cloned").length;
- let activeSlides = slider.find(".slick-slide.slick-active").length;
- let dots = slider.find(".slick-dots").children().length;
+ const { container } = render(
);
+ let totalSlides = getSlidesCount(container);
+ let clonedSlides = getClonesCount(container);
+ let activeSlides = getActiveSlidesCount(container);
+ let dots = getButtonsLength(container);
expect(totalSlides).toEqual(16);
expect(clonedSlides).toEqual(10);
expect(activeSlides).toEqual(4);
expect(dots).toEqual(2);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
test("Positioning test", () => {
- const slider = mount(
);
- let currentSlide = slider.find("div.slick-current");
- let activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(0);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 0,
- 1,
- 2,
- 3
- ]);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ const { container } = render(
);
+ let currentSlide = getCurrentSlide(container);
+ let activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([0, 1, 2, 3]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
test("Activity test", () => {
- const slider = mount(
);
- let currentSlide = slider.find("div.slick-current");
- let activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(0);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 0,
- 1,
- 2,
- 3
- ]);
+ const { container } = render(
);
+ let currentSlide = getCurrentSlide(container);
+ let activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([0, 1, 2, 3]);
- clickNext(slider);
+ clickNext(container);
- currentSlide = slider.find("div.slick-current");
- activeSlides = slider.find("div.slick-active");
- expect(currentSlide.props()["data-index"]).toEqual(4);
- expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([
- 4,
- 5,
- 6,
- 7
- ]);
- expect(beautify_html(slider.html())).toMatchSnapshot();
+ currentSlide = getCurrentSlide(container);
+ activeslides = getActiveSlides(container);
+ expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4);
+ expect(
+ Array.from(activeslides).map(slide =>
+ parseInt(slide.getAttribute("data-index"))
+ )
+ ).toEqual([4, 5, 6, 7]);
+ // expect(beautify_html(toString(container))).toMatchSnapshot();
});
});
diff --git a/examples/__tests__/__snapshots__/CenterMode.test.js.snap b/examples/__tests__/__snapshots__/CenterMode.test.js.snap
deleted file mode 100644
index cf1b20d1b..000000000
--- a/examples/__tests__/__snapshots__/CenterMode.test.js.snap
+++ /dev/null
@@ -1,373 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`CenterMode Tests Activity test 1`] = `
-"
-
Center Mode
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
"
-`;
-
-exports[`CenterMode Tests Counting test 1`] = `
-"
-
Center Mode
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
"
-`;
-
-exports[`CenterMode Tests Positioning test 1`] = `
-"
-
Center Mode
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
"
-`;
diff --git a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap b/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap
deleted file mode 100644
index 181930df8..000000000
--- a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap
+++ /dev/null
@@ -1,237 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`FocusOnSelect Tests Activity Test 1`] = `
-"
-
FocusOnSelect
-
Click on any slide to select and make it current slide
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
"
-`;
-
-exports[`FocusOnSelect Tests Activity Test 2`] = `
-"
-
FocusOnSelect
-
Click on any slide to select and make it current slide
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
"
-`;
diff --git a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap b/examples/__tests__/__snapshots__/MultipleItems.test.js.snap
deleted file mode 100644
index 7e4aabd01..000000000
--- a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap
+++ /dev/null
@@ -1,1477 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Multiple Items should have 3 active slides 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should have 3 dots 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should have 9 actual slides and (3(pre) + 9(post)) clone slides 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should show first 3 slides 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should show last 3 slides when last dot is clicked 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should show last 3 slides when previous button is clicked 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should show slides first 3 slides when middle dot is clicked 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should show slides from 4 to 6 when middle dot is clicked 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`Multiple Items should show slides from 4 to 6 when next button is clicked 1`] = `
-"
-
Multiple items
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
diff --git a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap b/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap
deleted file mode 100644
index 08be35767..000000000
--- a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap
+++ /dev/null
@@ -1,445 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Simple Slider Snapshots click on 3rd dot 1`] = `
-"
-
Single Item
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
- 1
- 2
- 3
- 4
- 5
- 6
-
-
-
"
-`;
-
-exports[`Simple Slider Snapshots click on next button 1`] = `
-"
-
Single Item
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
- 1
- 2
- 3
- 4
- 5
- 6
-
-
-
"
-`;
-
-exports[`Simple Slider Snapshots click on prev button 1`] = `
-"
-
Single Item
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
- 1
- 2
- 3
- 4
- 5
- 6
-
-
-
"
-`;
-
-exports[`Simple Slider Snapshots slider initial state 1`] = `
-"
-
Single Item
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
- 1
- 2
- 3
- 4
- 5
- 6
-
-
-
"
-`;
diff --git a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap b/examples/__tests__/__snapshots__/UnevenSets.test.js.snap
deleted file mode 100644
index b1dacdf75..000000000
--- a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap
+++ /dev/null
@@ -1,559 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`UnevenSets Finite Activity test 1`] = `
-"
-
Uneven sets (finite)
-
-
"
-`;
-
-exports[`UnevenSets Finite Counting test 1`] = `
-"
-
Uneven sets (finite)
-
-
"
-`;
-
-exports[`UnevenSets Finite Positioning test 1`] = `
-"
-
Uneven sets (finite)
-
-
"
-`;
-
-exports[`UnevenSets Infinite Activity test 1`] = `
-"
-
Uneven sets (infinite)
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`UnevenSets Infinite Counting test 1`] = `
-"
-
Uneven sets (infinite)
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
-
-exports[`UnevenSets Infinite Positioning test 1`] = `
-"
-
Uneven sets (infinite)
-
Previous
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Next
-
-
-
"
-`;
diff --git a/examples/__tests__/sample.test.js b/examples/__tests__/sample.test.js
index 4a17f8ea0..d2d276e62 100644
--- a/examples/__tests__/sample.test.js
+++ b/examples/__tests__/sample.test.js
@@ -1,5 +1,5 @@
import React from "react";
-import { mount } from "enzyme";
+import { fireEvent, render } from "@testing-library/react";
export default class Counter extends React.Component {
constructor(props) {
@@ -19,8 +19,22 @@ export default class Counter extends React.Component {
describe("sample counter test", function() {
it("mutliple counts", function() {
- const wrapper = mount(
);
- wrapper.simulate("click").simulate("click");
- expect(wrapper.text()).toEqual("Count 2");
+ const { container } = render(
);
+ const button = container.getElementsByTagName("Button")[0];
+ fireEvent(
+ button,
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ fireEvent(
+ button,
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+ expect(button.textContent).toEqual("Count 2");
});
});
diff --git a/examples/config.js b/examples/config.js
index ef00f7dbc..088a39e46 100644
--- a/examples/config.js
+++ b/examples/config.js
@@ -1,4 +1,6 @@
-export const baseUrl =
- process.env.NODE_ENV === "production"
- ? "https://s3.amazonaws.com/static.neostack.com/img/react-slick"
- : "/img/react-slick";
+// export const baseUrl =
+// process.env.NODE_ENV === "production"
+// ? "https://s3.amazonaws.com/static.neostack.com/img/react-slick"
+// : "/img/react-slick";
+
+export const baseUrl = "/img/react-slick";
diff --git a/gulpfile.js b/gulpfile.js
index 9cdbb5f6a..2859e2b9f 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -2,7 +2,6 @@
var gulp = require("gulp");
var del = require("del");
-var sass = require("gulp-sass");
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var assign = require("object-assign");
@@ -10,7 +9,7 @@ var opn = require("opn");
var UglifyJsPlugin = require("uglifyjs-webpack-plugin");
-const DEV_PORT = 8080;
+const DEV_PORT = process.env.DEV_PORT || 8080;
gulp.task("clean", function() {
return del(["./build/*"]);
@@ -30,22 +29,9 @@ gulp.task("copy", function() {
.pipe(gulp.dest("./build"));
});
-gulp.task("sass", function() {
- return gulp
- .src(["./docs/**/*.{scss,sass}"])
- .pipe(
- sass({
- includePaths: ["bower_components", "node_modules"],
- errLogToConsole: true
- })
- )
- .pipe(gulp.dest("./build"));
-});
-
gulp.task(
"watch",
- gulp.series(["copy", "sass"], function(done) {
- gulp.watch(["./docs/**/*.{scss,sass}"], gulp.parallel(["sass"]));
+ gulp.series(["copy"], function(done) {
gulp.watch(["./docs/index.html"], gulp.parallel(["copy"]));
gulp.watch(["./docs/docs.css"], gulp.parallel(["copy"]));
gulp.watch(["./docs/slick.css"], gulp.parallel(["copy"]));
@@ -56,7 +42,7 @@ gulp.task(
gulp.task(
"server",
- gulp.series(["watch", "copy", "sass"], function() {
+ gulp.series(["watch", "copy"], function() {
console.log("Start");
var myConfig = require("./webpack.config");
if (process.env.SINGLE_DEMO) {
diff --git a/jest.config.js b/jest.config.js
new file mode 100644
index 000000000..0ef9b2852
--- /dev/null
+++ b/jest.config.js
@@ -0,0 +1,5 @@
+module.exports = {
+ testEnvironment: "jsdom",
+ setupFilesAfterEnv: ["
/test-setup.js"],
+ testPathIgnorePatterns: ["/node_modules/", "e2e-tests"]
+};
diff --git a/package.json b/package.json
index d93171903..a66283efa 100644
--- a/package.json
+++ b/package.json
@@ -1,26 +1,27 @@
{
"name": "react-slick",
- "version": "0.28.1",
+ "version": "0.30.2",
"description": " React port of slick carousel",
"main": "./lib",
"scripts": {
- "start": "gulp server",
- "demo": "SINGLE_DEMO=true gulp server",
- "build-dev": "gulp clean && gulp sass && gulp copy && webpack",
+ "start": "NODE_OPTIONS=--openssl-legacy-provider gulp server",
+ "demo": "SINGLE_DEMO=true DEV_PORT=8000 NODE_OPTIONS=--openssl-legacy-provider gulp server",
+ "build-dev": "gulp clean && gulp copy && webpack",
"lib": "babel ./src --out-dir ./lib",
- "build": "npm run lib && gulp dist",
- "prepublish": "npm run build",
- "test": "npm run lint && jest",
- "test:watch": "jest --watch",
+ "build": "NODE_OPTIONS=--openssl-legacy-provider npm run lib && NODE_OPTIONS=--openssl-legacy-provider gulp dist",
+ "prepublishOnly": "npm run build",
"lint": "eslint src",
- "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html",
- "precommit": "lint-staged"
+ "gen": "node docs/scripts/generateExampleConfigs.js && node docs/scripts/generateExamples.js && xdg-open docs/jquery.html",
+ "precommit": "lint-staged",
+ "test": "jest",
+ "test-watch": "jest --watch",
+ "clear-jest": "jest --clearCache"
},
"author": "Kiran Abburi",
"license": "MIT",
"repository": {
"type": "git",
- "url": "https://github.com/akiran/react-slick"
+ "url": "git+https://github.com/akiran/react-slick.git"
},
"keywords": [
"slick",
@@ -32,47 +33,42 @@
],
"devDependencies": {
"@babel/cli": "^7.0.0",
- "@babel/core": "^7.1.2",
+ "@babel/core": "^7.16.0",
+ "@babel/eslint-parser": "^7.16.3",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
+ "@testing-library/jest-dom": "^5.16.4",
+ "@testing-library/react": "^13.3.0",
+ "@testing-library/user-event": "^14.3.0",
"autoprefixer": "^7.1.2",
"babel-core": "^7.0.0-bridge.0",
- "babel-eslint": "^9.0.0",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.4",
"babel-preset-airbnb": "^2.1.1",
"css-loader": "^2.1.1",
"deepmerge": "^1.1.0",
"del": "^2.2.2",
- "enzyme": "^3.2.0",
- "enzyme-adapter-react-16": "^1.1.0",
"es5-shim": "^4.5.9",
- "eslint": "^5.9.0",
- "eslint-plugin-import": "^2.9.0",
- "eslint-plugin-react": "^6.3.0",
+ "eslint": "^8.4.1",
+ "eslint-plugin-import": "^2.25.3",
+ "eslint-plugin-react": "^7.27.1",
"express": "^4.14.0",
"foundation-apps": "^1.2.0",
"gulp": "^4.0.0",
- "gulp-sass": "^4.0.0",
"husky": "^0.14.3",
- "jasmine-core": "^2.5.2",
- "jest": "^24.8.0",
- "jquery": "^3.2.1",
+ "jest": "^28.1.3",
+ "jest-environment-jsdom": "^28.1.3",
"js-beautify": "^1.7.5",
"json-loader": "^0.5.4",
- "lint-staged": "^7.0.3",
- "node-sass": "^4.5.2",
+ "lint-staged": "^12.1.2",
"opn": "^5.4.0",
"postcss-loader": "^1.3.3",
"prettier": "^1.14.3",
"raf": "^3.4.0",
- "react": "^16.0.0",
- "react-addons-test-utils": "^15.6.2",
- "react-dom": "^16.0.0",
- "react-test-renderer": "^16.0.0",
- "sass-loader": "^6.0.3",
+ "react": "^18.0.0",
+ "react-dom": "^18.0.0",
"sinon": "^2.1.0",
"slick-carousel": "^1.8.1",
"style-loader": "^0.16.1",
@@ -80,7 +76,8 @@
"webpack": "^4.21.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9",
- "why-did-you-update": "^0.1.1"
+ "why-did-you-update": "^0.1.1",
+ "regenerator-runtime": "^0.14.1"
},
"dependencies": {
"classnames": "^2.2.5",
@@ -90,17 +87,8 @@
"resize-observer-polyfill": "^1.5.0"
},
"peerDependencies": {
- "react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0",
- "react-dom": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0"
- },
- "jest": {
- "setupFiles": [
- "./test-setup.js"
- ],
- "testPathIgnorePatterns": [
- "/__tests__/scripts.js",
- "/__tests__/testUtils.js"
- ]
+ "react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0",
+ "react-dom": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0"
},
"lint-staged": {
"*.{js,json,md}": [
diff --git a/src/default-props.js b/src/default-props.js
index c98806a31..65f29d424 100644
--- a/src/default-props.js
+++ b/src/default-props.js
@@ -50,7 +50,9 @@ let defaultProps = {
useTransform: true,
variableWidth: false,
vertical: false,
- waitForAnimate: true
+ waitForAnimate: true,
+ asNavFor: null,
+ unslick: false
};
export default defaultProps;
diff --git a/src/inner-slider.js b/src/inner-slider.js
index b1eac5e6e..f9a207c7c 100644
--- a/src/inner-slider.js
+++ b/src/inner-slider.js
@@ -35,6 +35,7 @@ export class InnerSlider extends React.Component {
this.state = {
...initialState,
currentSlide: this.props.initialSlide,
+ targetSlide: this.props.initialSlide ? this.props.initialSlide : 0,
slideCount: React.Children.count(this.props.children)
};
this.callbackTimers = [];
@@ -133,7 +134,8 @@ export class InnerSlider extends React.Component {
}
if (
typeof prevProps[key] === "object" ||
- typeof prevProps[key] === "function"
+ typeof prevProps[key] === "function" ||
+ isNaN(prevProps[key])
) {
continue;
}
@@ -304,7 +306,8 @@ export class InnerSlider extends React.Component {
};
checkImagesLoad = () => {
let images =
- (this.list && this.list.querySelectorAll &&
+ (this.list &&
+ this.list.querySelectorAll &&
this.list.querySelectorAll(".slick-slide img")) ||
[];
let imagesCount = images.length,
@@ -316,8 +319,8 @@ export class InnerSlider extends React.Component {
image.onclick = () => image.parentNode.focus();
} else {
const prevClickHandler = image.onclick;
- image.onclick = () => {
- prevClickHandler();
+ image.onclick = e => {
+ prevClickHandler(e);
image.parentNode.focus();
};
}
diff --git a/src/slider.js b/src/slider.js
index 65d63a4b5..36225013e 100644
--- a/src/slider.js
+++ b/src/slider.js
@@ -4,7 +4,7 @@ import React from "react";
import { InnerSlider } from "./inner-slider";
import json2mq from "json2mq";
import defaultProps from "./default-props";
-import { canUseDOM } from "./utils/innerSliderUtils";
+import { canUseDOM, filterSettings } from "./utils/innerSliderUtils";
const enquire = canUseDOM() && require("enquire.js");
export default class Slider extends React.Component {
@@ -198,14 +198,17 @@ export default class Slider extends React.Component {
if (settings === "unslick") {
const className = "regular slider " + (this.props.className || "");
return {children}
;
- } else if (newChildren.length <= settings.slidesToShow) {
+ } else if (
+ newChildren.length <= settings.slidesToShow &&
+ !settings.infinite
+ ) {
settings.unslick = true;
}
return (
{newChildren}
diff --git a/src/track.js b/src/track.js
index bda460f94..4370b16da 100644
--- a/src/track.js
+++ b/src/track.js
@@ -67,6 +67,7 @@ const getSlideStyle = spec => {
style.left = -spec.index * parseInt(spec.slideWidth);
}
style.opacity = spec.currentSlide === spec.index ? 1 : 0;
+ style.zIndex = spec.currentSlide === spec.index ? 999 : 998;
if (spec.useCSS) {
style.transition =
"opacity " +
@@ -140,10 +141,7 @@ const renderSlides = spec => {
// if slide needs to be precloned or postcloned
if (spec.infinite && spec.fade === false) {
let preCloneNo = childrenCount - index;
- if (
- preCloneNo <= getPreClones(spec) &&
- childrenCount !== spec.slidesToShow
- ) {
+ if (preCloneNo <= getPreClones(spec)) {
key = -preCloneNo;
if (key >= startIndex) {
child = elem;
@@ -167,29 +165,27 @@ const renderSlides = spec => {
);
}
- if (childrenCount !== spec.slidesToShow) {
- key = childrenCount + index;
- if (key < endIndex) {
- child = elem;
- }
- slideClasses = getSlideClasses({ ...spec, index: key });
- postCloneSlides.push(
- React.cloneElement(child, {
- key: "postcloned" + getKey(child, key),
- "data-index": key,
- tabIndex: "-1",
- className: classnames(slideClasses, slideClass),
- "aria-hidden": !slideClasses["slick-active"],
- style: { ...(child.props.style || {}), ...childStyle },
- onClick: e => {
- child.props && child.props.onClick && child.props.onClick(e);
- if (spec.focusOnSelect) {
- spec.focusOnSelect(childOnClickOptions);
- }
- }
- })
- );
+ key = childrenCount + index;
+ if (key < endIndex) {
+ child = elem;
}
+ slideClasses = getSlideClasses({ ...spec, index: key });
+ postCloneSlides.push(
+ React.cloneElement(child, {
+ key: "postcloned" + getKey(child, key),
+ "data-index": key,
+ tabIndex: "-1",
+ className: classnames(slideClasses, slideClass),
+ "aria-hidden": !slideClasses["slick-active"],
+ style: { ...(child.props.style || {}), ...childStyle },
+ onClick: e => {
+ child.props && child.props.onClick && child.props.onClick(e);
+ if (spec.focusOnSelect) {
+ spec.focusOnSelect(childOnClickOptions);
+ }
+ }
+ })
+ );
}
});
diff --git a/src/utils/innerSliderUtils.js b/src/utils/innerSliderUtils.js
index d2496779d..b5d3bdc69 100644
--- a/src/utils/innerSliderUtils.js
+++ b/src/utils/innerSliderUtils.js
@@ -1,4 +1,5 @@
import React from "react";
+import defaultProps from "../default-props";
export function clamp(number, lowerBound, upperBound) {
return Math.max(lowerBound, Math.min(number, upperBound));
@@ -859,3 +860,14 @@ export const canUseDOM = () =>
window.document &&
window.document.createElement
);
+
+export const validSettings = Object.keys(defaultProps);
+
+export function filterSettings(settings) {
+ return validSettings.reduce((acc, settingName) => {
+ if (settings.hasOwnProperty(settingName)) {
+ acc[settingName] = settings[settingName];
+ }
+ return acc;
+ }, {});
+}
diff --git a/test-helpers.js b/test-helpers.js
deleted file mode 100644
index a778a0eca..000000000
--- a/test-helpers.js
+++ /dev/null
@@ -1,11 +0,0 @@
-export function repeatClicks(node, count) {
- for (let i = 0; i < count; i++) {
- node.simulate("click");
- }
-}
-
-export function delay(duration) {
- return new Promise(function(resolve) {
- setTimeout(resolve, duration);
- });
-}
diff --git a/test-setup.js b/test-setup.js
index 7f4f7b011..10cb36f33 100644
--- a/test-setup.js
+++ b/test-setup.js
@@ -1,11 +1,7 @@
-import "core-js/es6/map";
-import "core-js/es6/set";
-import "raf/polyfill";
+import "@testing-library/jest-dom/extend-expect";
+import "regenerator-runtime/runtime";
-import Enzyme from "enzyme";
-import Adapter from "enzyme-adapter-react-16";
-
-Enzyme.configure({ adapter: new Adapter() });
+//Fix for "matchMedia not present, legacy browsers require a polyfill jest" error
window.matchMedia =
window.matchMedia ||
function() {
@@ -15,9 +11,3 @@ window.matchMedia =
removeListener: function() {}
};
};
-
-window.requestAnimationFrame =
- window.requestAnimationFrame ||
- function(callback) {
- setTimeout(callback, 0);
- };
diff --git a/test-utils.js b/test-utils.js
new file mode 100644
index 000000000..265b79bfb
--- /dev/null
+++ b/test-utils.js
@@ -0,0 +1,86 @@
+import { render, fireEvent, waitFor, screen } from "@testing-library/react";
+
+export function getSlidesCount(container) {
+ return container.getElementsByClassName("slick-slide").length;
+}
+
+export function getSlides(container) {
+ return container.getElementsByClassName("slick-slide");
+}
+
+export function getClonesCount(container) {
+ return container.getElementsByClassName("slick-cloned").length;
+}
+
+export function getActiveSlidesCount(container) {
+ return container.querySelectorAll(".slick-slide.slick-active").length;
+}
+
+export function getCurrentSlide(container) {
+ return container.querySelector(".slick-current");
+}
+
+export function getCurrentSlideContent(container) {
+ const slide = container.querySelector(".slick-current");
+ return slide.textContent;
+}
+
+export function getButtons(container) {
+ return container.querySelectorAll(".slick-dots button");
+}
+
+export function getButtonsListItem(container) {
+ return container.querySelectorAll(".slick-dots")[0].children;
+}
+export function getButtonsLength(container) {
+ return container.querySelectorAll(".slick-dots")[0].children.length;
+}
+export function hasClass(element, classname) {
+ if (element.className != undefined) {
+ return element.classList.contains(classname);
+ }
+ return false;
+}
+export function getActiveButton(container) {
+ return Array.from(
+ container.querySelectorAll(".slick-dots .slick-active button")
+ ).map(e => e.textContent);
+}
+// export function getCurrentSlideIdState(container) {
+// return parseInt(getCurrentSlide(container).getAttribute("data-index")) + 1;
+// }
+// export function activeSlides(container) {
+// return container.querySelectorAll(".slick-slide.slick-active");
+// }
+export function getActiveSlide(container) {
+ return container.querySelector(".slick-slide.slick-active");
+}
+
+export function getActiveSlides(container) {
+ return container.querySelectorAll(".slick-slide.slick-active");
+}
+
+export function getActiveSlidesText(container) {
+ const slides = getActiveSlides(container);
+ return Array.from(slides).map(e => e.textContent);
+}
+
+export function clickNext(container) {
+ fireEvent(
+ container.getElementsByClassName("slick-next")[0],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+}
+
+export function clickPrevious(container) {
+ fireEvent(
+ container.getElementsByClassName("slick-prev")[0],
+ new MouseEvent("click", {
+ bubbles: true,
+ cancelable: true
+ })
+ );
+}
diff --git a/webpack.config.js b/webpack.config.js
index e4e96d462..c6804359a 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -27,7 +27,10 @@ module.exports = {
]
},
resolve: {
- extensions: [".js", ".jsx"]
+ extensions: [".js", ".jsx"],
+ alias: {
+ "react-slick": path.resolve(__dirname, "src/index.js")
+ }
},
plugins: [new webpack.IgnorePlugin(/vertx/)],
devServer: {