Skip to content

Commit

Permalink
test setup with testing library
Browse files Browse the repository at this point in the history
  • Loading branch information
akiran committed Jul 26, 2022
1 parent 2f7fdf5 commit 472c848
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions examples/__tests__/SimpleSlider.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import SimpleSlider from "../SimpleSlider";
import { render, fireEvent, waitFor, screen } from "@testing-library/react";

describe("SimpleSlider example", () => {
test("render", () => {
const { container } = render(<SimpleSlider />);
expect(container.getElementsByClassName("slick-slide").length).toBe(13);
});
});
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/test-setup.js"]
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"prepublish": "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"
"precommit": "lint-staged",
"test": "jest",
"test-watch": "jest --watch"
},
"author": "Kiran Abburi",
"license": "MIT",
Expand All @@ -40,6 +42,8 @@
"@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",
"autoprefixer": "^7.1.2",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.8.0",
Expand All @@ -56,6 +60,8 @@
"foundation-apps": "^1.2.0",
"gulp": "^4.0.0",
"husky": "^0.14.3",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"js-beautify": "^1.7.5",
"json-loader": "^0.5.4",
"lint-staged": "^12.1.2",
Expand Down
12 changes: 12 additions & 0 deletions test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "@testing-library/jest-dom/extend-expect";

//Fix for "matchMedia not present, legacy browsers require a polyfill jest" error
window.matchMedia =
window.matchMedia ||
function() {
return {
matches: false,
addListener: function() {},
removeListener: function() {}
};
};

0 comments on commit 472c848

Please sign in to comment.