+ Caption text
+
+
+
-
-
- Staged HOC with caption and customizations
-
-
+
- Caption text
-
-
-
+ }
+ >
+ Caption text
+
+
`;
diff --git a/packages/framework/use-slots/src/useSlots.samples.test.tsx b/packages/framework/use-slots/src/useSlots.samples.test.tsx
index 9f5f8f4f63..77434ade47 100644
--- a/packages/framework/use-slots/src/useSlots.samples.test.tsx
+++ b/packages/framework/use-slots/src/useSlots.samples.test.tsx
@@ -4,8 +4,7 @@ import type { CSSProperties } from 'react';
import { mergeProps } from '@fluentui-react-native/merge-props';
import { withSlots, stagedComponent } from '@fluentui-react-native/use-slot';
-import { mount } from 'enzyme';
-import toJson from 'enzyme-to-json';
+import * as renderer from 'react-test-renderer';
import { buildUseSlots } from './buildUseSlots';
@@ -73,23 +72,21 @@ describe('useSlots sample code test suite', () => {
});
BoldTextStaged.displayName = 'BoldTextStaged';
- /**
- * The demos of the code use enzyme with JSDom to show the full tree. This has the side effect of doubling up primitive elements in the output
- * JSON. This is an issue with rendering react-native with enzyme but in real usage the nodes only render once.
- */
it('renders sample 1 - the two types of basic bold text components', () => {
const styleToMerge: TextStyle = { color: 'black' };
/**
* First render the staged component. This invokes the wrapper that was built by the stagedComponent function
*/
- const wrapper = mount(
-
- Staged component at one level
- Standard component of a single level
-
,
- );
- expect(toJson(wrapper)).toMatchSnapshot();
+ const wrapper = renderer
+ .create(
+
+ Staged component at one level
+ Standard component of a single level
+
,
+ )
+ .toJSON();
+ expect(wrapper).toMatchSnapshot();
});
/**
@@ -159,13 +156,15 @@ describe('useSlots sample code test suite', () => {
/**
* First render the staged component. This invokes the wrapper that was built by the stagedComponent function
*/
- const wrapper = mount(
-
- Staged component with two levels
- Standard component with two levels
-
,
- );
- expect(toJson(wrapper)).toMatchSnapshot();
+ const wrapper = renderer
+ .create(
+
+ Staged component with two levels
+ Standard component with two levels
+
,
+ )
+ .toJSON();
+ expect(wrapper).toMatchSnapshot();
});
/**
@@ -250,9 +249,6 @@ describe('useSlots sample code test suite', () => {
});
CaptionedHeaderStaged.displayName = 'CaptionedHeaderStaged';
- /**
- * Render to enzyme snapshots
- */
it('renders sample 3 - the two types of higher order header components', () => {
const styleToMerge: ViewStyle = { backgroundColor: 'gray', borderColor: 'purple', borderWidth: 1 };
@@ -260,27 +256,29 @@ describe('useSlots sample code test suite', () => {
* Render the two sets of components. Note in the snapshots how the render tree layers for the standard approach are starting
* to add up.
*/
- const wrapper = mount(
-
- --- SIMPLE USAGE COMPARISON ---
- Standard HOC
- Staged HOC
- --- COMPARISON WITH CAPTIONS ---
-
- Standard HOC with Caption
-
-
- Staged HOC with Caption
-
- --- COMPARISON WITH CAPTIONS AND CUSTOMIZATIONS ---
-
- Standard HOC with caption and customizations
-
-
- Staged HOC with caption and customizations
-
-
,
- );
- expect(toJson(wrapper)).toMatchSnapshot();
+ const wrapper = renderer
+ .create(
+
+ --- SIMPLE USAGE COMPARISON ---
+ Standard HOC
+ Staged HOC
+ --- COMPARISON WITH CAPTIONS ---
+
+ Standard HOC with Caption
+
+
+ Staged HOC with Caption
+
+ --- COMPARISON WITH CAPTIONS AND CUSTOMIZATIONS ---
+
+ Standard HOC with caption and customizations
+
+
+ Staged HOC with caption and customizations
+
+
,
+ )
+ .toJSON();
+ expect(wrapper).toMatchSnapshot();
});
});
diff --git a/packages/framework/use-styling/src/__snapshots__/useStyling.samples.test.tsx.snap b/packages/framework/use-styling/src/__snapshots__/useStyling.samples.test.tsx.snap
index f71cd5970b..e672727631 100644
--- a/packages/framework/use-styling/src/__snapshots__/useStyling.samples.test.tsx.snap
+++ b/packages/framework/use-styling/src/__snapshots__/useStyling.samples.test.tsx.snap
@@ -1,7 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`useStyling samples Sample1Text rendering with no overrides 1`] = `
-
+
+ Sample1a
+
+`;
+
+exports[`useStyling samples Sample1Text rendering with some custom settings in the theme 1`] = `
+
+ Sample1b
+
+`;
+
+exports[`useStyling samples Sample2Text rendering with defaults and a color override 1`] = `
+
-
- Sample1a
-
+ Sample2 with defaults
-
-`;
-
-exports[`useStyling samples Sample1Text rendering with some custom settings in the theme 1`] = `
-
-
- Sample1b
-
+ Sample2 with color override via prop
-
-`;
-
-exports[`useStyling samples Sample2Text rendering with defaults and a color override 1`] = `
-
-
-
-
-
- Sample2 with defaults
-
-
-
-
-
-
- Sample2 with color override via prop
-
-
-
-
`;
exports[`useStyling samples Sample2Text rendering with some custom settings in the theme 1`] = `
-
-
-
-
- Sample2 with theme overrides set
-
-
-
-
-
-
- Sample2 with theme and color prop override
-
-
-
-
+
+ Sample2 with theme overrides set
+
+
+ Sample2 with theme and color prop override
+
`;
diff --git a/packages/framework/use-styling/src/useStyling.samples.test.tsx b/packages/framework/use-styling/src/useStyling.samples.test.tsx
index 1921a62a00..dca810c8f9 100644
--- a/packages/framework/use-styling/src/useStyling.samples.test.tsx
+++ b/packages/framework/use-styling/src/useStyling.samples.test.tsx
@@ -2,8 +2,9 @@ import * as React from 'react';
import type { TextProps, ColorValue } from 'react-native';
import { Text, View } from 'react-native';
-import { mount } from 'enzyme';
-import toJson from 'enzyme-to-json';
+// TODO: Without this import, we are somehow getting the global `expect` function from Jasmine instead of Jest.
+import { expect } from '@jest/globals';
+import * as renderer from 'react-test-renderer';
import { buildProps } from './buildProps';
import type { ThemeHelper, UseStylingOptions } from './buildUseStyling';
@@ -46,13 +47,6 @@ const baseTheme: Theme = {
const current = { theme: baseTheme };
-/**
- * this wrapper solves the (so-far) inexplicable type errors from the matchers in typescript
- */
-function snapshotTestTree(tree: any) {
- (expect(toJson(tree)) as any).toMatchSnapshot();
-}
-
/**
* Because the buildUseStyling utility is not opinionated about theming, the theming is injected via
* a theme helper implementation. This allows for a framework to build an opinionated version with
@@ -137,8 +131,8 @@ describe('useStyling samples', () => {
/** first render the component with no updates */
it('Sample1Text rendering with no overrides', () => {
- const tree = mount(Sample1a);
- snapshotTestTree(tree);
+ const tree = renderer.create(Sample1a).toJSON();
+ expect(tree).toMatchSnapshot();
});
/** now re-theme the component via the components in the theme */
@@ -151,8 +145,8 @@ describe('useStyling samples', () => {
},
},
});
- const tree = mount(Sample1b);
- snapshotTestTree(tree);
+ const tree = renderer.create(Sample1b).toJSON();
+ expect(tree).toMatchSnapshot();
});
/**
@@ -218,13 +212,15 @@ describe('useStyling samples', () => {
/** rendering the Sample2 component with the base theme */
it('Sample2Text rendering with defaults and a color override', () => {
themeHelper.setActive();
- const tree = mount(
-
- Sample2 with defaults
- Sample2 with color override via prop
- ,
- );
- snapshotTestTree(tree);
+ const tree = renderer
+ .create(
+
+ Sample2 with defaults
+ Sample2 with color override via prop
+ ,
+ )
+ .toJSON();
+ expect(tree).toMatchSnapshot();
});
/** now re-theme the component via the components in the theme */
@@ -241,12 +237,14 @@ describe('useStyling samples', () => {
},
},
});
- const tree = mount(
-
- Sample2 with theme overrides set
- Sample2 with theme and color prop override
- ,
- );
- snapshotTestTree(tree);
+ const tree = renderer
+ .create(
+
+ Sample2 with theme overrides set
+ Sample2 with theme and color prop override
+ ,
+ )
+ .toJSON();
+ expect(tree).toMatchSnapshot();
});
});
diff --git a/packages/framework/use-tokens/src/__snapshots__/useTokens.samples.test.tsx.snap b/packages/framework/use-tokens/src/__snapshots__/useTokens.samples.test.tsx.snap
index c0f0fa1712..64eb6e26e4 100644
--- a/packages/framework/use-tokens/src/__snapshots__/useTokens.samples.test.tsx.snap
+++ b/packages/framework/use-tokens/src/__snapshots__/useTokens.samples.test.tsx.snap
@@ -1,7 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`useTokens samples Sample1Text rendering with no overrides 1`] = `
-
+
+ Sample1a
+
+`;
+
+exports[`useTokens samples Sample1Text rendering with some custom settings in the theme 1`] = `
+
+ Sample1b
+
+`;
+
+exports[`useTokens samples Sample2Text rendering with defaults and a color override 1`] = `
+
-
- Sample1a
-
+ Sample2 with defaults
-
-`;
-
-exports[`useTokens samples Sample1Text rendering with some custom settings in the theme 1`] = `
-
-
- Sample1b
-
+ Sample2 with color override via prop
-
-`;
-
-exports[`useTokens samples Sample2Text rendering with defaults and a color override 1`] = `
-
-
-
-
-
- Sample2 with defaults
-
-
-
-
-
-
- Sample2 with color override via prop
-
-
-
-
`;
exports[`useTokens samples Sample2Text rendering with some custom settings in the theme 1`] = `
-
-
-
-
- Sample2 with theme overrides set
-
-
-
-
-
-
- Sample2 with theme and color prop override
-
-
-
-
+
+ Sample2 with theme overrides set
+
+
+ Sample2 with theme and color prop override
+
`;
diff --git a/packages/framework/use-tokens/src/useTokens.samples.test.tsx b/packages/framework/use-tokens/src/useTokens.samples.test.tsx
index db2b44e267..6df2527aeb 100644
--- a/packages/framework/use-tokens/src/useTokens.samples.test.tsx
+++ b/packages/framework/use-tokens/src/useTokens.samples.test.tsx
@@ -4,8 +4,9 @@ import { Text, View } from 'react-native';
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
import { mergeStyles } from '@fluentui-react-native/merge-props';
-import { mount } from 'enzyme';
-import toJson from 'enzyme-to-json';
+// TODO: Without this import, we are somehow getting the global `expect` function from Jasmine instead of Jest.
+import { expect } from '@jest/globals';
+import * as renderer from 'react-test-renderer';
import { buildUseTokens } from './buildUseTokens';
@@ -52,13 +53,6 @@ const setActiveTheme = (theme?: Partial) => {
current.theme = (theme && immutableMerge(baseTheme, theme as Theme)) || baseTheme;
};
-/**
- * this wrapper solves the (so-far) inexplicable type errors from the matchers in typescript
- */
-function snapshotTestTree(tree: any) {
- (expect(toJson(tree)) as any).toMatchSnapshot();
-}
-
/**
* Helper function used to look up a component in the theme. Having this injected allows this module to not be dependent on the shape of
* the theme used.
@@ -139,8 +133,8 @@ describe('useTokens samples', () => {
/** first render the component with no updates */
it('Sample1Text rendering with no overrides', () => {
- const tree = mount(Sample1a);
- snapshotTestTree(tree);
+ const tree = renderer.create(Sample1a).toJSON();
+ expect(tree).toMatchSnapshot();
});
/** now re-theme the component via the components in the theme */
@@ -153,8 +147,8 @@ describe('useTokens samples', () => {
},
},
});
- const tree = mount(Sample1b);
- snapshotTestTree(tree);
+ const tree = renderer.create(Sample1b).toJSON();
+ expect(tree).toMatchSnapshot();
});
/**
@@ -192,13 +186,15 @@ describe('useTokens samples', () => {
/** rendering the Sample2 component with the base theme */
it('Sample2Text rendering with defaults and a color override', () => {
- const tree = mount(
-
- Sample2 with defaults
- Sample2 with color override via prop
- ,
- );
- snapshotTestTree(tree);
+ const tree = renderer
+ .create(
+
+ Sample2 with defaults
+ Sample2 with color override via prop
+ ,
+ )
+ .toJSON();
+ expect(tree).toMatchSnapshot();
});
/** now re-theme the component via the components in the theme */
@@ -211,12 +207,14 @@ describe('useTokens samples', () => {
},
},
});
- const tree = mount(
-
- Sample2 with theme overrides set
- Sample2 with theme and color prop override
- ,
- );
- snapshotTestTree(tree);
+ const tree = renderer
+ .create(
+
+ Sample2 with theme overrides set
+ Sample2 with theme and color prop override
+ ,
+ )
+ .toJSON();
+ expect(tree).toMatchSnapshot();
});
});
diff --git a/packages/utils/interactive-hooks/src/__tests__/useConst.test.tsx b/packages/utils/interactive-hooks/src/__tests__/useConst.test.tsx
index 410c632ada..c53e45937e 100644
--- a/packages/utils/interactive-hooks/src/__tests__/useConst.test.tsx
+++ b/packages/utils/interactive-hooks/src/__tests__/useConst.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { validateHookValueNotChanged } from '@fluentui-react-native/test-tools';
-import { mount } from 'enzyme';
+import * as renderer from 'react-test-renderer';
import { useConst } from '../useConst';
@@ -18,12 +18,12 @@ describe('useConst', () => {
return {value};
};
- const wrapper = mount();
- const firstValue = wrapper.text();
+ const wrapper = renderer.create();
+ const firstValue = wrapper.toJSON();
// Re-render the component
- wrapper.update();
+ wrapper.update();
// Text should be the same
- expect(wrapper.text()).toBe(firstValue);
+ expect(wrapper.toJSON()).toBe(firstValue);
// Function shouldn't have been called again
expect(initializer).toHaveBeenCalledTimes(1);
});
@@ -36,9 +36,9 @@ describe('useConst', () => {
return {value};
};
- const wrapper = mount();
+ const wrapper = renderer.create();
// Re-render the component
- wrapper.update();
+ wrapper.update();
// Function shouldn't have been called again
expect(initializer).toHaveBeenCalledTimes(1);
});
diff --git a/packages/utils/interactive-hooks/src/__tests__/useControllableValue.test.tsx b/packages/utils/interactive-hooks/src/__tests__/useControllableValue.test.tsx
index 634041bfc6..987cd34f60 100644
--- a/packages/utils/interactive-hooks/src/__tests__/useControllableValue.test.tsx
+++ b/packages/utils/interactive-hooks/src/__tests__/useControllableValue.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { validateHookValueNotChanged } from '@fluentui-react-native/test-tools';
-import { mount } from 'enzyme';
+import * as renderer from 'react-test-renderer';
import { useControllableValue } from '../useControllableValue';
@@ -13,16 +13,16 @@ describe('useControllableValue', () => {
return ;
};
- const wrapper1 = mount();
+ const wrapper1 = renderer.create();
expect(resultValue!).toBe(true);
- wrapper1.setProps({ value: false });
+ wrapper1.update();
expect(resultValue!).toBe(false);
- const wrapper2 = mount();
+ const wrapper2 = renderer.create();
expect(resultValue!).toBe(false);
- wrapper2.setProps({ value: true });
+ wrapper2.update();
expect(resultValue!).toBe(true);
});
@@ -33,7 +33,7 @@ describe('useControllableValue', () => {
return ;
};
- mount();
+ renderer.create();
expect(resultValue!).toBe(true);
});
@@ -44,10 +44,10 @@ describe('useControllableValue', () => {
return ;
};
- const wrapper = mount();
+ const wrapper = renderer.create();
expect(resultValue!).toBe(true);
- wrapper.setProps({ defaultValue: false });
+ wrapper.update();
expect(resultValue!).toBe(true);
});