aboutsummaryrefslogtreecommitdiff
path: root/test/docs
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2024-12-28 04:25:06 +0100
committerGitHub <[email protected]>2024-12-28 03:25:06 +0000
commite6d27a353ec9c82e60b31c8d833768141beb4dab (patch)
treee9b728c03218d458149cb711909034170f61f3fd /test/docs
parent817f8a01d93378e00c03cf73154fcec34fd5feef (diff)
downloadfaker-e6d27a353ec9c82e60b31c8d833768141beb4dab.tar.xz
faker-e6d27a353ec9c82e60b31c8d833768141beb4dab.zip
docs(api): add refresh button to examples (#3301)
* docs(api): add refresh button to examples * chore: improve button behavior slightly * chore: improve output format * chore: ignore examples without recordable results * temp * chore: use svg button * chore: use json5 format for test * chore: simplify result formatting * test: add formatting tests * test: add e2e refresh test * test: use static test values * chore: fix regex * chore: simplify refresh placeholder * Update cypress/e2e/example-refresh.cy.ts * fix: handle property after function call * Apply suggestions from code review Co-authored-by: Shinigami <[email protected]> * Apply suggestions from code review Co-authored-by: Shinigami <[email protected]> * Apply suggestions from code review Co-authored-by: Shinigami <[email protected]> * chore: format * chore: add comment --------- Co-authored-by: Shinigami <[email protected]>
Diffstat (limited to 'test/docs')
-rw-r--r--test/docs/__snapshots__/format.spec.ts.snap19
-rw-r--r--test/docs/format.spec.ts69
2 files changed, 88 insertions, 0 deletions
diff --git a/test/docs/__snapshots__/format.spec.ts.snap b/test/docs/__snapshots__/format.spec.ts.snap
new file mode 100644
index 00000000..36679523
--- /dev/null
+++ b/test/docs/__snapshots__/format.spec.ts.snap
@@ -0,0 +1,19 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`formatResult > should format Date 1`] = `"'2025-01-01T00:00:00.000Z'"`;
+
+exports[`formatResult > should format array 1`] = `"[ 1, '2' ]"`;
+
+exports[`formatResult > should format bigint 1`] = `"135464154865415n"`;
+
+exports[`formatResult > should format number 1`] = `"123"`;
+
+exports[`formatResult > should format object 1`] = `"{ 'a': 1, 'b': '2' }"`;
+
+exports[`formatResult > should format string 1`] = `"'a simple string'"`;
+
+exports[`formatResult > should format string with new lines 1`] = `"'string\\nwith\\nnew\\nlines'"`;
+
+exports[`formatResult > should format string with special characters 1`] = `"'string with "special" characters'"`;
+
+exports[`formatResult > should format undefined 1`] = `"undefined"`;
diff --git a/test/docs/format.spec.ts b/test/docs/format.spec.ts
new file mode 100644
index 00000000..bc4a0d66
--- /dev/null
+++ b/test/docs/format.spec.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from 'vitest';
+import { formatResult } from '../../docs/.vitepress/components/api-docs/format';
+
+describe('formatResult', () => {
+ it('should format undefined', () => {
+ const value = undefined;
+ const actual = formatResult(value);
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toBe('undefined');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format bigint', () => {
+ const actual = formatResult(135464154865415n);
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format object', () => {
+ const actual = formatResult({ a: 1, b: '2' });
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format array', () => {
+ const actual = formatResult([1, '2']);
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format string', () => {
+ const actual = formatResult('a simple string');
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format string with special characters', () => {
+ const actual = formatResult('string with "special" characters');
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format string with new lines', () => {
+ const actual = formatResult('string\nwith\nnew\nlines');
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format number', () => {
+ const actual = formatResult(123);
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+
+ it('should format Date', () => {
+ const actual = formatResult(new Date(Date.UTC(2025, 0, 1)));
+
+ expect(actual).toBeTypeOf('string');
+ expect(actual).toMatchSnapshot();
+ });
+});