-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
107 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-flow" | ||
"@babel/preset-typescript" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
interface Model extends Object {} | ||
|
||
interface ModelDefinition extends Object { | ||
[model: string]: Function | ||
} | ||
|
||
interface Overrides extends Object { | ||
[attribute: string]: any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"parser": "@typescript-eslint/parser", | ||
"extends": [ | ||
"plugin:flowtype/recommended", | ||
"plugin:jest/recommended", | ||
"standard" | ||
], | ||
"plugins": [ | ||
"flowtype", | ||
"@typescript-eslint", | ||
"jest" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
language: node_js | ||
node_js: | ||
- '8' | ||
- '6' | ||
node_js: [10, 12, 13, 14] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import factory from '..' | ||
|
||
const keys = <O extends Object>(obj: O): Array<keyof O> => { | ||
return Object.keys(obj) as Array<keyof O> | ||
} | ||
|
||
const validate = (user: Model, overrides = {}): void => { | ||
['id', 'email', 'name'].forEach(key => expect(Object.prototype.hasOwnProperty.call(user, key)).toBe(true)) | ||
keys(overrides).forEach(key => expect(user[key]).toBe(overrides[key])) | ||
} | ||
|
||
describe('factoria', (): void => { | ||
it('generates a model with name', (): void => validate(factory('user'))) | ||
|
||
it("overrides a model's properties", () => { | ||
validate(factory('user', { email: 'foo@bar.net' }), { email: 'foo@bar.net' }) | ||
}) | ||
|
||
it('generates several models', (): void => { | ||
const users = factory('user', 2) as Model[] | ||
expect(users).toHaveLength(2) | ||
users.forEach(validate) | ||
}) | ||
|
||
it("overrides multiple models' properties", (): void => { | ||
const users = factory('user', 3, { email: 'foo@bar.net' }) as Model[] | ||
expect(users).toHaveLength(3) | ||
users.forEach(user => validate(user, { email: 'foo@bar.net' })) | ||
}) | ||
|
||
it('supports define chaining', (): void => { | ||
expect(factory.define('foo', faker => ({}))).toEqual(factory) | ||
}) | ||
|
||
it('supports functions as property overrides', (): void => { | ||
validate(factory('user', { email: () => 'foo@bar.net' }), { email: 'foo@bar.net' }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"strict": true, | ||
"module": "es2015", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"noImplicitThis": false, | ||
"downlevelIteration": true | ||
}, | ||
"include": [ | ||
"index.ts", | ||
"test/**/*.ts" | ||
] | ||
} |