-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: agrega testes a todas ls utils
- Loading branch information
Showing
13 changed files
with
193 additions
and
35 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
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
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,11 +1,37 @@ | ||
import Emulator from "../Emulator"; | ||
import createProxy from "./createProxy"; | ||
|
||
const scope = new Emulator(); | ||
const $ = new Emulator(); | ||
|
||
describe("(function) createProxy", () => { | ||
it("Requires a scope parameter that represents the emulator instance", () => { | ||
const proxy = createProxy(scope); | ||
expect(typeof proxy).toBe("function"); | ||
it("Returns an existing proxy", () => { | ||
const proxy = $.use(); | ||
const sameProxy = createProxy($, proxy); | ||
expect(proxy).toBe(sameProxy); | ||
}); | ||
|
||
it("Returns an existing proxy by reference key", () => { | ||
const refKey = "test"; | ||
const proxy = $.useRef(refKey); | ||
const sameProxy = createProxy($, proxy, undefined, refKey); | ||
|
||
expect(proxy).toBe(sameProxy); | ||
}); | ||
|
||
it("Adds a new reference key", () => { | ||
const refKey = "new"; | ||
const refKeyExisted = $.refs.includes(refKey); | ||
|
||
createProxy($, undefined, undefined, refKey); | ||
|
||
expect(refKeyExisted).toBe(false); | ||
expect($.refs.includes(refKey)).toBe(true); | ||
}); | ||
|
||
it("Adds any target value to a proxy", () => { | ||
const target = "target"; | ||
const proxy = createProxy($, target); | ||
|
||
expect($.target(proxy)).toBe(target); | ||
}); | ||
}); |
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,5 +1,30 @@ | ||
import Emulator from "../Emulator"; | ||
import findProxy from "./findProxy"; | ||
|
||
const $ = new Emulator(); | ||
|
||
describe("(function) findProxy", () => { | ||
it("Runs an exotic proxy emulator", () => { | ||
expect(true).toBeTruthy(); | ||
it("Returns undefined when a proxy is not found", () => { | ||
const param = "notProxy_notTarget"; | ||
const proxy = findProxy(param); | ||
|
||
expect(proxy).toBeUndefined(); | ||
}); | ||
|
||
it("Returns the same proxy if the search parameter is a proxy", () => { | ||
const param = $.use(); | ||
const proxy = findProxy(param); | ||
|
||
expect(proxy).not.toBeUndefined(); | ||
expect(typeof proxy).toBe("function"); | ||
expect(proxy).toBe(param); | ||
}); | ||
|
||
it("Finds a proxy by target reference", () => { | ||
const target = []; | ||
const proxy = $.use(target); | ||
const search = findProxy(target); | ||
|
||
expect(search).toBe(proxy); | ||
}); | ||
}); |
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,5 +1,20 @@ | ||
import Emulator from "../Emulator"; | ||
import getPayload from "./getPayload"; | ||
|
||
const $ = new Emulator(); | ||
|
||
describe("(function) getPayload", () => { | ||
it("Runs an exotic proxy emulator", () => { | ||
expect(true).toBeTruthy(); | ||
it("Returns a payload object from a proxy", () => { | ||
const proxy = $.use(); | ||
const payload = getPayload($, proxy); | ||
|
||
expect(payload).toEqual({ encoded: true, value: 1 }); | ||
}); | ||
|
||
it("Returns a payload object from a non proxy value", () => { | ||
const value = null; | ||
const payload = getPayload($, value); | ||
|
||
expect(payload).toEqual({ encoded: false, value }); | ||
}); | ||
}); |
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,5 +1,29 @@ | ||
import Emulator from "../Emulator"; | ||
import isTraceable from "./isTraceable"; | ||
|
||
const $ = new Emulator(); | ||
|
||
describe("(function) isTraceable", () => { | ||
it("Runs an exotic proxy emulator", () => { | ||
expect(true).toBeTruthy(); | ||
it("Returns true when the parameter is a non-null object or a function that is not a proxy", () => { | ||
// define prossible targets | ||
const trueTargets = [[], {}, function () {}, () => {}, function* () {}]; | ||
const falseTargets = [ | ||
null, | ||
undefined, | ||
"string", | ||
$.use(), | ||
10, | ||
NaN, | ||
Infinity, | ||
true, | ||
false, | ||
Symbol(), | ||
]; | ||
|
||
const traceable = trueTargets.every(isTraceable); | ||
const untraceable = falseTargets.some(isTraceable); | ||
|
||
expect(traceable).toBe(true); | ||
expect(untraceable).toBe(false); | ||
}); | ||
}); |
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,5 +1,44 @@ | ||
import Emulator from "../Emulator"; | ||
import proxyGenerator from "./proxyGenerator"; | ||
|
||
const $ = new Emulator(); | ||
|
||
const proxyA = $.use(); | ||
const proxyB = $.use(); | ||
const proxyC = $.use(); | ||
|
||
describe("(function*) proxyGenerator", () => { | ||
it("Runs an exotic proxy emulator", () => { | ||
expect(true).toBeTruthy(); | ||
it("Returns an IterableIterator of all non-revoked proxies in the emulator instance", () => { | ||
const iterator = proxyGenerator($); | ||
|
||
expect(iterator.next().value).toBe(proxyA); | ||
expect(iterator.next().value).toBe(proxyB); | ||
expect(iterator.next().value).toBe(proxyC); | ||
expect(iterator.next().done).toBe(true); | ||
}); | ||
|
||
it("Returns an IterableIterator of all non-revoked proxies in the emulator instance in reverse order", () => { | ||
const iterator = proxyGenerator($, undefined, true); | ||
|
||
expect(iterator.next().value).toBe(proxyC); | ||
expect(iterator.next().value).toBe(proxyB); | ||
expect(iterator.next().value).toBe(proxyA); | ||
expect(iterator.next().done).toBe(true); | ||
}); | ||
|
||
it("Returns an IterableIterator of all non-revoked proxies in the emulator instance starting from an specific proxy in time", () => { | ||
const iterator = proxyGenerator($, proxyB); | ||
|
||
expect(iterator.next().value).toBe(proxyB); | ||
expect(iterator.next().value).toBe(proxyC); | ||
expect(iterator.next().done).toBe(true); | ||
}); | ||
|
||
it("Returns an IterableIterator of all non-revoked proxies in the emulator instance starting from an specific proxy in time backwards", () => { | ||
const iterator = proxyGenerator($, proxyB, true); | ||
|
||
expect(iterator.next().value).toBe(proxyB); | ||
expect(iterator.next().value).toBe(proxyA); | ||
expect(iterator.next().done).toBe(true); | ||
}); | ||
}); |
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,5 +1,30 @@ | ||
import Emulator from "../Emulator"; | ||
import revokeProxy from "./revokeProxy"; | ||
|
||
const $ = new Emulator(); | ||
|
||
describe("(function) revokeProxy", () => { | ||
it("Runs an exotic proxy emulator", () => { | ||
expect(true).toBeTruthy(); | ||
it("Returns false when the parameter is not a proxy", () => { | ||
const param = [100]; | ||
const isrevoked = revokeProxy($, param); | ||
|
||
expect(isrevoked).toBe(false); | ||
}); | ||
|
||
it("Returns true when the parameter is a proxy", () => { | ||
const proxy = $.use(); | ||
const isrevoked = revokeProxy($, proxy); | ||
|
||
expect(isrevoked).toBe(true); | ||
expect(proxy).toThrow(); | ||
}); | ||
|
||
it("Returns true when the parameter is a proxy's target", () => { | ||
const target = {}; | ||
const proxy = $.use(target); | ||
const isrevoked = revokeProxy($, target); | ||
|
||
expect(isrevoked).toBe(true); | ||
expect(proxy).toThrow(); | ||
}); | ||
}); |