{"id":16641276,"url":"https://github.com/cmstead/datamother.js","last_synced_at":"2025-06-22T04:02:47.122Z","repository":{"id":26971128,"uuid":"30434614","full_name":"cmstead/DataMother.js","owner":"cmstead","description":"DataMother is/will be a test data management tool for unit testing JS.","archived":false,"fork":false,"pushed_at":"2023-01-03T22:15:43.000Z","size":486,"stargazers_count":2,"open_issues_count":14,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T04:02:39.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmstead.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-06T21:51:51.000Z","updated_at":"2023-01-31T16:36:37.000Z","dependencies_parsed_at":"2023-01-14T05:43:08.900Z","dependency_job_id":null,"html_url":"https://github.com/cmstead/DataMother.js","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/cmstead/DataMother.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2FDataMother.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2FDataMother.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2FDataMother.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2FDataMother.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmstead","download_url":"https://codeload.github.com/cmstead/DataMother.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmstead%2FDataMother.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261233103,"owners_count":23128194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T07:46:05.948Z","updated_at":"2025-06-22T04:02:42.108Z","avatar_url":"https://github.com/cmstead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataMother #\r\n\r\nDataMother is a test data construction library to make creating and using test data fast, easy and predictable. By centralizing data in factories with declared dependencies, your tests will always use the correct data format which will make tests more reliable.  When real-world data contracts change, simply change your data files and then use your tests to identify where things went wrong!\r\n\r\nDataMother makes writing tests fast and making correct tests easier.\r\n\r\n## API ##\r\n\r\nThis is the basic API, examples are listed below.\r\n\r\n- dataMother.register -- `name:string, factory:function =\u003e undefined`\r\n    - Register registers a mother object with DataMother for data creation later. Register requires a key and an object and returns undefined.\r\n\r\n- dataMother.buildData -- `name:string, options:[object] =\u003e *`\r\n    - Build returns a new instance of test data as well as nested instances of depency objects.\r\n\r\n- dataMother.buildDataArray -- `name:string, length:variant\u003cundefined, leftBoundedInt\u003c1\u003e\u003e, options:[object] =\u003e array\u003c*\u003e`\r\n    - BuildDataArray returns a new array of data containing a number of data elements equal to the length passed in.  When no length is provided, the length will be 1.\r\n\r\n## Examples ##\r\n\r\n- **A sample motherfile in Node might look like the following:**\r\n\r\n```\r\n'use strict';\r\n\r\nfunction nestedTestData (simpleNestedTestDataArray, simpleTestData) {\r\n    return {\r\n        ownProperty: 'something',\r\n        dependencyData: simpleNestedTestDataArray,\r\n        simpleTestData: simpleTestData\r\n    };\r\n}\r\n\r\nnestedTestData['@dependencies'] = ['simpleNestedTestData', 'simpleTestData'];\r\n\r\nmodule.exports = nestedTestData;\r\n```\r\n\r\n\r\n- **Likewise, in the client a motherfile might look like this:**\r\n\r\n```\r\n(function () {\r\n    'use strict';\r\n\r\n    function nestedTestData (simpleNestedTestDataArray, simpleTestData) {\r\n        return {\r\n            ownProperty: 'something',\r\n            dependencyData: simpleNestedTestDataArray,\r\n            simpleTestData: simpleTestData\r\n        };\r\n    }\r\n\r\n    nestedTestData['@dependencies'] = ['simpleNestedTestData', 'simpleTestData'];\r\n\r\n    dataMother.register('nestedTestData', nestedTestData);\r\n})()\r\n```\r\n\r\n- **Capturing data from DataMother is as easy as the following:**\r\n\r\n```\r\nconst simpleData = dataMother.buildData('simpleTestData');\r\nconst simpleData = dataMother.buildDataArray('simpleTestData', 5);\r\n```\r\n\r\n\r\n- **Properties can be data factories so data can be dynamically generated per test**\r\n\r\n```\r\n'use strict';\r\n\r\nfunction testDataWithPropertyFactory () {\r\n    return {\r\n        property1: 'foo',\r\n        property2: function (index) {\r\n            // index always starts at 0\r\n            return 'bar' + index;\r\n        }\r\n    };\r\n}\r\n\r\nmodule.exports = testDataWithPropertyFactory;\r\n```\r\n- **Data can be constructed with data properties via the options object**\r\n\r\n```\r\nconst options = {\r\n    optionsData: {\r\n        testDataWithPropertyFactory: {\r\n            value: 'testValue'\r\n        }\r\n    }\r\n}\r\n\r\n// Constructing a single data value\r\nmotherContainer.buildData('testDataWithPropertyFactory', options);\r\n\r\n// Constructing an array of data\r\nmotherContainer.buildDataArray('testDataWithPropertyFactory', 3, options);\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmstead%2Fdatamother.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmstead%2Fdatamother.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmstead%2Fdatamother.js/lists"}