Skip to content

Commit

Permalink
Merge pull request #88 from pmcelhaney/use-example-values
Browse files Browse the repository at this point in the history
configure JSON Schema Faker to use the examples
  • Loading branch information
pmcelhaney committed Jul 18, 2022
2 parents 02c9efb + de5e92b commit 8c11f01
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-dingos-lay.md
@@ -0,0 +1,5 @@
---
"counterfact": minor
---

use example values (if present) when generating random data
2 changes: 2 additions & 0 deletions src/tools.js
@@ -1,5 +1,7 @@
import JSONSchemaFaker from "json-schema-faker";

JSONSchemaFaker.option("useExamplesValue", true);

export class Tools {
constructor({ headers = {} } = {}) {
this.headers = headers;
Expand Down
6 changes: 6 additions & 0 deletions test/tools.test.js
Expand Up @@ -42,4 +42,10 @@ describe("tools", () => {

expect(typeof tools.randomFromSchema({ type: "integer" })).toBe("number");
});

it("randomFromSchema() uses examples", () => {
const tools = new Tools();

expect(tools.randomFromSchema({ type: "integer", examples: [5] })).toBe(5);
});
});

0 comments on commit 8c11f01

Please sign in to comment.