Skip to content

Commit

Permalink
remove the rest of enzyme
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Jan 29, 2025
1 parent 77d699f commit d589076
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 573 deletions.
6 changes: 0 additions & 6 deletions packages/libraries/core/jest.setup.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/utils/test-tools/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Test-tools

This is a dev environment only private package designed to aid in testing components via jest and enzyme
This is a dev environment only private package designed to aid in testing components via jest
3 changes: 1 addition & 2 deletions packages/utils/test-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fluentui-react-native/test-tools",
"version": "0.1.1",
"description": "Tools and mocks for testing components using jest and enzyme",
"description": "Tools and mocks for testing components using jest",
"main": "lib-commonjs/index.js",
"module": "src/index.ts",
"typings": "lib/index.d.ts",
Expand All @@ -12,7 +12,6 @@
"clean": "fluentui-scripts clean",
"depcheck": "fluentui-scripts depcheck",
"lint": "fluentui-scripts eslint",
"test": "fluentui-scripts jest",
"update-snapshots": "fluentui-scripts jest -u",
"prettier": "fluentui-scripts prettier",
"prettier-fix": "fluentui-scripts prettier --fix true"
Expand Down
43 changes: 43 additions & 0 deletions packages/utils/test-tools/src/baseTests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react';

import * as renderer from 'react-test-renderer';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function validateHookValueNotChanged<TValues extends NonNullable<any>[]>(
testDescription: string,
useHook: () => TValues,
useHookAgain?: () => TValues,
) {
it(testDescription || 'returns the same value(s) each time', () => {
let latestValues: TValues | undefined;
let callCount = 0;

const TestComponent: React.FunctionComponent = () => {
callCount++;
// eslint-disable-next-line react-hooks/rules-of-hooks
latestValues = callCount === 1 ? useHook() : (useHookAgain || useHook)();
return <React.Fragment />;
};

const wrapper = renderer.create(<TestComponent />);
expect(callCount).toBe(1);
const firstValues = latestValues;
expect(firstValues).toBeDefined();
latestValues = undefined;

wrapper.update(<TestComponent />);
expect(callCount).toBe(2);
expect(latestValues).toBeDefined();
expect(latestValues.length).toEqual(firstValues!.length);

for (let i = 0; i < latestValues!.length; i++) {
try {
expect(latestValues![i]).toBe(firstValues![i]);
} catch (err) {
// Make a more informative error message
const valueText = latestValues![i].toString();
expect('').toBe(`Identity of value at index ${i} has changed. This might help identify it:\n${valueText}`);
}
}
});
}
82 changes: 0 additions & 82 deletions packages/utils/test-tools/src/enzymeTests.test.tsx

This file was deleted.

138 changes: 0 additions & 138 deletions packages/utils/test-tools/src/enzymeTests.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions packages/utils/test-tools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { checkReRender, checkRenderConsistency, compareTrees, snapshotPropTree, validateHookValueNotChanged } from './enzymeTests';
export type { JSXProducer, PropTreeFilter, PropTreeSnapshot } from './enzymeTests';
export { validateHookValueNotChanged } from './baseTests';
export { mockTheme } from './mockTheme';
4 changes: 0 additions & 4 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@
"@react-native-community/cli-platform-ios": "^12.1.1",
"@react-native/metro-babel-transformer": "^0.73.0",
"@rnx-kit/jest-preset": "^0.1.14",
"@types/enzyme": "^3.10.5",
"@types/es6-collections": "^0.5.29",
"@types/es6-promise": "0.0.32",
"@types/jest": "^29.0.0",
"@types/node": "^12.11.2",
"@types/react-test-renderer": "16.9.0",
"@uifabric/prettier-rules": "^7.0.3",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.5",
"depcheck": "^1.0.0",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.5.0",
"find-up": "^5.0.0",
"fs-extra": "^7.0.1",
"jest": "^29.2.1",
Expand Down
5 changes: 1 addition & 4 deletions scripts/src/configs/configureJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ export function configureJest(customConfig?: object): object {
KeyCodes: path.resolve(__dirname, 'jest/jest-mock.js'),
// Jest is picking up the hoisted version of lru-cache, which is
// incompatible from the version required by semver
'lru-cache': require.resolve('lru-cache', {paths:[require.resolve('semver')]}),
'lru-cache': require.resolve('lru-cache', { paths: [require.resolve('semver')] }),
},
moduleFileExtensions,
moduleDirectories: nodeModulesToRoot(),

snapshotSerializers: ['enzyme-to-json/serializer'],

// use babel-jest to transform files including typescript
transform: {
'^.+\\.(js|ts|tsx)?$': 'babel-jest',
Expand All @@ -49,7 +47,6 @@ export function configureReactNativeJest(platform?: PlatformValue, customConfig?
return jestPreset(ensurePlatform(platform, 'ios'), {
roots: ['<rootDir>/src'],
verbose: false,
setupFilesAfterEnv: [path.join(__dirname, 'jest', 'setupEnzyme.js')],
...customConfig,
});
}
49 changes: 0 additions & 49 deletions scripts/src/configs/jest/setupEnzyme.js

This file was deleted.

Loading

0 comments on commit d589076

Please sign in to comment.