Skip to content

Commit cbe216e

Browse files
committed
Refactor tests to use array assertions instead of snapshots
Updated multiple test files to replace inline snapshot assertions with direct array comparisons for toolbar node content and console log outputs. Removed obsolete Jest snapshot file. These changes improve test clarity and maintainability.
1 parent 3484361 commit cbe216e

File tree

4 files changed

+18
-56
lines changed

4 files changed

+18
-56
lines changed

packages/faustwp-cli/tests/healthCheck/__snapshots__/validateFaustEnvVars.test.ts.snap

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,22 @@ describe('healthCheck/validateFaustEnvVars', () => {
5858
process.env.NEXT_PUBLIC_WORDPRESS_URL = 'https://headless.local';
5959
process.env.FAUST_SECRET_KEY = 'invalid-secret-key';
6060

61+
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
62+
6163
fetchMock.post(
62-
'https://headless.local/wp-json/faustwp/v1/validate_secret_key',
64+
'https://headless.local/?rest_route=/faustwp/v1/validate_secret_key',
6365
{
6466
status: 401,
6567
},
6668
);
6769

6870
await validateFaustEnvVars();
6971

70-
return expect(Promise.resolve(validateFaustEnvVars())).toMatchSnapshot(
71-
`Ensure your FAUST_SECRET_KEY environment variable matches your Secret Key in the Faust WordPress plugin settings`,
72+
expect(consoleLogSpy).toHaveBeenCalledWith(
73+
expect.stringContaining('Ensure your FAUST_SECRET_KEY environment variable matches your Secret Key'),
7274
);
75+
76+
consoleLogSpy.mockRestore();
7377
});
7478
});
7579

packages/faustwp-cli/tests/healthCheck/validateNextWordPressUrl.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ describe('healthCheck/validateNextWordPressUrl', () => {
4848

4949
await validateNextWordPressUrl();
5050
expect(consoleLogSpy).toHaveBeenCalledWith(
51-
expect.stringContaining(
52-
'Validation Failed: Your Faust front-end site URL value is misconfigured. It should NOT match the `NEXT_PUBLIC_WORDPRESS_URL.',
53-
),
51+
expect.stringContaining('Validation Failed, Faust is shutting down:'),
52+
expect.stringContaining('Your Faust front-end site URL value is misconfigured'),
5453
);
5554
expect(mockExit).toHaveBeenCalledWith(1);
5655
expect(fetchMock).toHaveFetched(

packages/faustwp-core/tests/components/Toolbar/Toolbar.test.tsx

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,7 @@ test('renders a default list of nodes in the primary section if seedNode is not
129129
testToolBarNode(
130130
toolBars[0],
131131
3,
132-
`
133-
Array [
134-
"WordPress",
135-
"",
136-
"GraphiQL IDE",
137-
]
138-
`,
132+
['WordPress', '', 'GraphiQL IDE'],
139133
);
140134
});
141135

@@ -159,13 +153,7 @@ test('renders an Edit Post Node, in the primary section if seedNode is provided
159153
testToolBarNode(
160154
toolBars[0],
161155
3,
162-
`
163-
Array [
164-
"WordPress",
165-
"Edit Post",
166-
"GraphiQL IDE",
167-
]
168-
`,
156+
['WordPress', 'Edit Post', 'GraphiQL IDE'],
169157
);
170158
});
171159

@@ -187,14 +175,7 @@ test('renders an Account Node in the secondary section', async () => {
187175
testToolBarNode(
188176
toolBars[1],
189177
4,
190-
`
191-
Array [
192-
"Howdy, Edit ProfileLog Out",
193-
"",
194-
"Edit Profile",
195-
"Log Out",
196-
]
197-
`,
178+
['Howdy, Edit ProfileLog Out', '', 'Edit Profile', 'Log Out'],
198179
);
199180
});
200181

@@ -218,13 +199,7 @@ test('renders an Edit Post Node, if seedNode is not provided and is preview', as
218199
testToolBarNode(
219200
toolBars[0],
220201
3,
221-
`
222-
Array [
223-
"WordPress",
224-
"Edit Post",
225-
"GraphiQL IDE",
226-
]
227-
`,
202+
['WordPress', 'Edit Post', 'GraphiQL IDE'],
228203
);
229204
});
230205

@@ -244,13 +219,7 @@ test('does not render an Edit Post Node, if there is no seedNode and it is not a
244219
testToolBarNode(
245220
toolBars[0],
246221
3,
247-
`
248-
Array [
249-
"WordPress",
250-
"",
251-
"GraphiQL IDE",
252-
]
253-
`,
222+
['WordPress', '', 'GraphiQL IDE'],
254223
);
255224
});
256225

@@ -276,18 +245,11 @@ test('Uses `toolbarNodes` hook to add nodes', async () => {
276245
);
277246
await waitFor(() => queryByAttribute('id', dom.container, 'wpadminbar'));
278247
const toolBars = screen.getAllByRole('list', { name: /toolbar/i });
279-
// Secondary Toolbar
248+
// Primary Toolbar
280249
testToolBarNode(
281250
toolBars[0],
282251
4,
283-
`
284-
Array [
285-
"WordPress",
286-
"Edit Post",
287-
"GraphiQL IDE",
288-
"Test Node",
289-
]
290-
`,
252+
['WordPress', 'Edit Post', 'GraphiQL IDE', 'Test Node'],
291253
);
292254
});
293255

@@ -318,11 +280,11 @@ class TestAddToolbarNodePlugin {
318280
function testToolBarNode(
319281
toolBar: HTMLElement,
320282
expectedLen: number,
321-
expectedContent: string,
283+
expectedContent: string[],
322284
) {
323285
const { getAllByRole } = within(toolBar);
324286
const items = getAllByRole('listitem');
325287
expect(items.length).toBe(expectedLen);
326288
const toolBarNames = items.map((item) => item.textContent);
327-
expect(toolBarNames).toMatchInlineSnapshot(expectedContent);
289+
expect(toolBarNames).toEqual(expectedContent);
328290
}

0 commit comments

Comments
 (0)