Skip to content

Commit

Permalink
Jest now running
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Nov 27, 2024
1 parent e6ae64e commit 17f9c09
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 242 deletions.
3 changes: 3 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Notes for next 4.x release.

- Minimum react version updated to 16.8.0 (hooks)
6 changes: 5 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"presets": ["@babel/preset-react"]
"presets": [
"@babel/preset-env",
["@babel/preset-react", { "runtime": "automatic" }],
"@babel/preset-typescript"
]
}
27 changes: 1 addition & 26 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const config = {
collectCoverage: true,
coverageDirectory: 'temp/coverage',
coverageProvider: 'v8',
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
Expand Down Expand Up @@ -39,35 +37,12 @@ const config = {
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

Expand Down Expand Up @@ -117,7 +92,7 @@ const config = {

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// '/node_modules/',
// "\\.pnp\\.[^\\/]+$"
// ],

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
"deploy": "gh-pages -d example/build"
},
"peerDependencies": {
"react": ">=15",
"react-dom": ">=15"
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"devDependencies": {
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.6",
"@babel/preset-env": "^7.26.0",
"@babel/preset-stage-0": "^7.8.3",
"@babel/preset-react": "^7.25.9",
"@babel/preset-typescript": "^7.26.0",
"country-region-data": "^3.1.0",
"cross-env": "^5.1.4",
"eslint": "^8.57.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"gh-pages": "^1.2.0",
"minimalist": "^1.0.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rollup": "^4.27.4",
"typescript": "^5.7.2",
"@rollup/plugin-babel": "^6.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/RegionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { RegionDropdownProps } from './rcrs.types';

export const RegionDropdown: FC<RegionDropdownProps> = ({
onChange,
value,
country = '',
value = '',
onBlur = () => null,
id = '',
name = 'rcrs-region',
Expand Down
167 changes: 167 additions & 0 deletions src/__tests__/CountryDropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// import React from 'react';
// import { CountryDropdown, CountryRegionData } from '../../dist/rcrs.es';
// import Enzyme, { shallow } from 'enzyme';

// const Adapter = require('enzyme-adapter-react-16');
// Enzyme.configure({ adapter: new Adapter() });

// describe('CountryDropdown', () => {
// it('sets ID attribute', () => {
// const wrapper = shallow(<CountryDropdown id="id-attribute" />);
// expect(wrapper.find('#id-attribute').length).toBe(1);
// expect(wrapper.find('#fake-id-attribute').length).toBe(0);
// });

// it('classes attribute gets recognized', () => {
// const wrapper = shallow(<CountryDropdown classes="one two three" />);
// expect(wrapper.find('select').hasClass('one two three')).toBe(true);
// });

// it('passes arbitrary properties', () => {
// const wrapper = shallow(
// <CountryDropdown style={{ color: 'red' }} data-whatever="5" />
// );
// expect(wrapper.find('select').getElement().props.style.color).toBe('red');
// expect(wrapper.find('select').getElement().props['data-whatever']).toBe(
// '5'
// );
// });

// describe('name attribute', () => {
// it('falls back on default name attribute when not specified', () => {
// const wrapper = shallow(<CountryDropdown />);
// expect(wrapper.find('select').getElement().props.name).toBe(
// 'rcrs-country'
// );
// });

// it('sets explicit name attribute', () => {
// const wrapper = shallow(<CountryDropdown name="name-attribute" />);
// expect(wrapper.find('select[name="name-attribute"]').length).toBe(1);
// expect(wrapper.find('select[name="fake-name-attribute"]').length).toBe(0);
// });
// });

// describe('disabled attribute', () => {
// it('disabled attribute not on by default', () => {
// const wrapper = shallow(<CountryDropdown />);
// expect(wrapper.find('select').getElement().props.disabled).toBe(false);
// });
// it('disabled attribute', () => {
// const wrapper = shallow(<CountryDropdown disabled={true} />);
// expect(wrapper.find('select').getElement().props.disabled).toBe(true);
// });
// });

// describe('default blank option', () => {
// it('showDefaultOption = false removes the default option', () => {
// const wrapper = shallow(<CountryDropdown showDefaultOption={false} />);
// expect(wrapper.find('option').length).toBe(CountryRegionData.length);
// });

// it('confirm default label is "Select Country"', () => {
// const wrapper = shallow(<CountryDropdown />);
// expect(wrapper.find('select').childAt(0).text()).toBe('Select Country');
// });

// it('defaultOptionLabel', () => {
// const customLabel = 'Holy moly I am a custom label!';
// const wrapper = shallow(
// <CountryDropdown defaultOptionLabel={customLabel} />
// );
// expect(wrapper.find('select').childAt(0).text()).toBe(customLabel);
// });
// });

// describe('country list', () => {
// it('outputs the list of countries', () => {
// const wrapper = shallow(<CountryDropdown />);
// expect(wrapper.find('option').length).toBe(CountryRegionData.length + 1); // 1 for the "Select Country" default option
// });

// it('respects the blacklist', () => {
// const blacklist = ['GB', 'CA', 'US'];
// const wrapper = shallow(
// <CountryDropdown blacklist={blacklist} showDefaultOption={false} />
// );
// expect(wrapper.find('option').length).toBe(
// CountryRegionData.length - blacklist.length
// );

// // confirm a non-blacklist item appears
// expect(wrapper.find('option[value="Afghanistan"]').length).toBe(1);

// // confirm none of the blacklist item appears
// expect(wrapper.find('option[value="United Kingdom"]').length).toBe(0);
// expect(wrapper.find('option[value="Canada"]').length).toBe(0);
// expect(wrapper.find('option[value="United States"]').length).toBe(0);
// });

// it('respects the whitelist', () => {
// const whitelist = ['GB', 'CA', 'US'];
// const wrapper = shallow(
// <CountryDropdown whitelist={whitelist} showDefaultOption={false} />
// );
// expect(wrapper.find('option').length).toBe(whitelist.length);

// // confirm the expected items appear
// expect(wrapper.find('option[value="United Kingdom"]').length).toBe(1);
// expect(wrapper.find('option[value="Canada"]').length).toBe(1);
// expect(wrapper.find('option[value="United States"]').length).toBe(1);
// });
// });

// describe('valueType', () => {
// it('confirm value is full country name by default', () => {
// const wrapper = shallow(<CountryDropdown showDefaultOption={false} />);
// expect(wrapper.find('select').childAt(0).getElement().props.value).toBe(
// CountryRegionData[0][0]
// );
// });

// it('confirm explicit valueType="full" also sets full country name', () => {
// const wrapper = shallow(
// <CountryDropdown showDefaultOption={false} valueType="full" />
// );
// expect(wrapper.find('select').childAt(0).getElement().props.value).toBe(
// CountryRegionData[0][0]
// );
// });

// it('confirm valueType="short" outputs country short code', () => {
// const wrapper = shallow(
// <CountryDropdown showDefaultOption={false} valueType="short" />
// );
// expect(wrapper.find('select').childAt(0).getElement().props.value).toBe(
// CountryRegionData[0][1]
// );
// });
// });

// describe('labelType', () => {
// it('confirm label type is full country name by default', () => {
// const wrapper = shallow(<CountryDropdown showDefaultOption={false} />);
// expect(wrapper.find('select').childAt(0).text()).toBe(
// CountryRegionData[0][0]
// );
// });

// it('confirm label type is full country name when explicitly set', () => {
// const wrapper = shallow(
// <CountryDropdown showDefaultOption={false} labelType="full" />
// );
// expect(wrapper.find('select').childAt(0).text()).toBe(
// CountryRegionData[0][0]
// );
// });

// it('confirm label type is the country shortcode when set', () => {
// const wrapper = shallow(
// <CountryDropdown showDefaultOption={false} labelType="short" />
// );
// expect(wrapper.find('select').childAt(0).text()).toBe(
// CountryRegionData[0][1]
// );
// });
// });
// });
Loading

0 comments on commit 17f9c09

Please sign in to comment.