-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
13 changed files
with
192 additions
and
87 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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 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
39 changes: 21 additions & 18 deletions
39
packages/vest/src/core/validate/__snapshots__/spec.js.snap
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,23 +1,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test validate suite wrapper Context creation Should create a new context object with initialized suite data 1`] = ` | ||
Object { | ||
"result": Object { | ||
"addToSkipped": [Function], | ||
"markAsDone": [Function], | ||
"markFailure": [Function], | ||
"markTestRun": [Function], | ||
"output": Object { | ||
"errorCount": 0, | ||
"name": "formName", | ||
"skipped": Array [], | ||
"testCount": 0, | ||
"tested": Array [], | ||
"tests": Object {}, | ||
"warnCount": 0, | ||
exports[`Test validate suite wrapper Context creation Should call \`runWithContext\` with tests as the argument 1`] = ` | ||
Array [ | ||
Object { | ||
"result": Object { | ||
"addToSkipped": [Function], | ||
"markAsDone": [Function], | ||
"markFailure": [Function], | ||
"markTestRun": [Function], | ||
"output": Object { | ||
"errorCount": 0, | ||
"name": "formName", | ||
"skipped": Array [], | ||
"testCount": 0, | ||
"tested": Array [], | ||
"tests": Object {}, | ||
"warnCount": 0, | ||
}, | ||
"pending": Array [], | ||
"setPending": [Function], | ||
}, | ||
"pending": Array [], | ||
"setPending": [Function], | ||
}, | ||
} | ||
[Function], | ||
] | ||
`; |
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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as globalObject } from "./globalObject"; | ||
export { default as runWithContext } from "./runWithContext"; | ||
export { default as singleton } from "./singleton"; | ||
export { default as throwError } from "./throwError"; |
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,16 @@ | ||
import Context from "../../core/Context"; | ||
|
||
/** | ||
* Initializes a Vest context and runs a callback function. | ||
* @param {Object} parent Parent context. | ||
* @param {Function} fn Function to run after creating the context. | ||
* @returns {*} callback funcion output. | ||
*/ | ||
const runWithContext = (parent, fn) => { | ||
new Context(parent); | ||
const res = fn(); | ||
Context.clear(); | ||
return res; | ||
}; | ||
|
||
export default runWithContext; |
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,55 @@ | ||
import faker from "faker"; | ||
|
||
describe("runWithContext", () => { | ||
let parent, fn, mockContext, result, runWithContext, singleton; | ||
|
||
beforeEach(() => { | ||
singleton = require("../singleton"); | ||
|
||
result = faker.random.word(); | ||
parent = { [faker.random.word()]: faker.lorem.word() }; | ||
fn = jest.fn(() => result); | ||
singleton = require("../singleton"); | ||
runWithContext = require("."); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("Should call callback function after creating the context", () => { | ||
expect(singleton.useContext()).toBeFalsy(); | ||
const fn = jest.fn(() => { | ||
expect(singleton.useContext()).toMatchObject(parent); | ||
}); | ||
|
||
runWithContext(parent, fn); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Should return with the callback function's return value", () => { | ||
expect(runWithContext(parent, fn)).toBe(result); | ||
}); | ||
|
||
describe("Calls to context", () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
mockContext = jest.fn(); | ||
mockContext.clear = jest.fn(); | ||
jest.mock("../../core/Context/", () => ({ | ||
__esModule: true, | ||
default: mockContext, | ||
})); | ||
singleton = require("../singleton"); | ||
runWithContext = require("."); | ||
runWithContext(parent, fn); | ||
}); | ||
it("Should create a new context with the parent object", () => { | ||
expect(mockContext).toHaveBeenCalledWith(parent); | ||
}); | ||
|
||
it("Should clear the created context", () => { | ||
expect(mockContext.clear).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
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