Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate enzyme tests to testing-library #52

Merged
merged 6 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"src/index.d.ts"
],
"scripts": {
"lint": "eslint ./src ./examples",
"lint": "eslint ./src ./tests ./examples",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curiously the test files weren't checked by eslint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting. Thanks for adding them!

"test": "yarn lint && yarn test:only",
"test:only": "jest --no-cache --verbose --coverage",
"test:dev": "jest --watchAll --no-cache --verbose --coverage",
Expand Down
4 changes: 2 additions & 2 deletions tests/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ let eventObj = {};

describe('actions test', () => {
beforeAll(() => {
showCallback = jest.fn(e => {
showCallback = jest.fn((e) => {
eventObj = e;
});
window.addEventListener(MENU_SHOW, showCallback);

hideCallback = jest.fn(e => {
hideCallback = jest.fn((e) => {
eventObj = e;
});
window.addEventListener(MENU_HIDE, hideCallback);
Expand Down
60 changes: 30 additions & 30 deletions tests/sub-menu-test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
"use strict";

import React from "react";
import { shallow, mount } from "enzyme";
import { expect } from "chai";

import SubMenu from "../src/submenu";
import React from 'react';
import { shallow, mount } from 'enzyme';
import { expect } from 'chai';

describe("<SubMenu/>", () => {
it("should have `react-context-menu-item` & `submenu` classes", () => {
const wrapper = shallow(<SubMenu title="foo"/>);
import SubMenu from '../src/submenu';

expect(wrapper).to.have.className("react-context-menu-item");
expect(wrapper).to.have.className("submenu");
describe('<SubMenu/>', () => {
it('should have `react-context-menu-item` & `submenu` classes', () => {
const wrapper = shallow(<SubMenu title='foo' />);

expect(wrapper).to.have.className('react-context-menu-item');
expect(wrapper).to.have.className('submenu');
});

it("<a/> should have `react-context-menu-link` class", () => {
const wrapper = shallow(<SubMenu title="foo"/>);
it('<a/> should have `react-context-menu-link` class', () => {
const wrapper = shallow(<SubMenu title='foo' />);

expect(wrapper.find("a")).to.have.className("react-context-menu-link");
expect(wrapper.find("a")).to.not.have.className("disabled");
expect(wrapper.find('a')).to.have.className('react-context-menu-link');
expect(wrapper.find('a')).to.not.have.className('disabled');
});

it("<a/> should have `disabled` class when disabled", () => {
const wrapper = shallow(<SubMenu title="foo" disabled/>);
it('<a/> should have `disabled` class when disabled', () => {
const wrapper = shallow(<SubMenu title='foo' disabled />);

expect(wrapper.find("a")).to.have.className("react-context-menu-link");
expect(wrapper.find("a")).to.have.className("disabled");
expect(wrapper.find('a')).to.have.className('react-context-menu-link');
expect(wrapper.find('a')).to.have.className('disabled');
});

it("should render `title` inside `<a/>`", () => {
const title = Math.random().toString(36),
wrapper = shallow(<SubMenu title={title} disabled/>);
it('should render `title` inside `<a/>`', () => {
const title = Math.random().toString(36);
const wrapper = shallow(<SubMenu title={title} disabled />);

expect(wrapper.find("a")).to.have.text(title);
expect(wrapper.find('a')).to.have.text(title);
});

xit("should open submenu `onMouseEnter`", function() {
const wrapper = mount(<SubMenu title="foo" hoverDelay={0}/>);
xit('should open submenu `onMouseEnter`', function () {
const wrapper = mount(<SubMenu title='foo' hoverDelay={0} />);

wrapper.find(".submenu").simulate("mouseEnter");
expect(wrapper).to.have.state("visible", true);
wrapper.find('.submenu').simulate('mouseEnter');
expect(wrapper).to.have.state('visible', true);
});

xit("should not open submenu `onMouseEnter` when disabled", function() {
const wrapper = mount(<SubMenu title="foo" hoverDelay={0} disabled/>);
xit('should not open submenu `onMouseEnter` when disabled', function () {
const wrapper = mount(<SubMenu title='foo' hoverDelay={0} disabled />);

wrapper.simulate("mouseenter");
expect(wrapper).to.have.state("visible", false);
wrapper.simulate('mouseenter');
expect(wrapper).to.have.state('visible', false);
});
});
30 changes: 15 additions & 15 deletions tests/sub-menu-wrapper-test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"use strict";

import React from "react";
import { shallow, mount } from "enzyme";

import React from 'react';
import { shallow, mount } from 'enzyme';
// import sinon from "sinon";
import { expect } from "chai";
import { expect } from 'chai';

import SubMenuWrapper from "../src/submenu/wrapper";
import SubMenuWrapper from '../src/submenu/wrapper';
// import monitor from "../src/monitor";

describe("<SubMenuWrapper/>", () => {
it("should have `react-context-menu` class", () => {
const wrapper = shallow(<SubMenuWrapper/>);
describe('<SubMenuWrapper/>', () => {
it('should have `react-context-menu` class', () => {
const wrapper = shallow(<SubMenuWrapper />);

expect(wrapper.hasClass("react-context-menu")).to.equal(true);
expect(wrapper.hasClass('react-context-menu')).to.equal(true);
});

it("should be invisible by default", () => {
const wrapper = mount(<SubMenuWrapper/>);
it('should be invisible by default', () => {
const wrapper = mount(<SubMenuWrapper />);

expect(wrapper.find("nav")).to.have.style("display", "none");
expect(wrapper.find('nav')).to.have.style('display', 'none');
});

it("should be visible when `visible` is passed", () => {
const wrapper = mount(<SubMenuWrapper visible/>);
it('should be visible when `visible` is passed', () => {
const wrapper = mount(<SubMenuWrapper visible />);

expect(wrapper.find("nav")).to.have.style("display", "block");
expect(wrapper.find('nav')).to.have.style('display', 'block');
});
});