Skip to content

Commit

Permalink
add back the unit tests from index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
kalisjoshua committed Feb 3, 2022
1 parent 0c4ea84 commit cab6262
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions metho.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import * as Metho from './metho.js'

describe("metho library", () => {
it("should export a data Symbol", () => {
expect(Metho.data).toBeTruthy()
})

it("should augment multiple prototypes", () => {
const nonHash = Symbol("No hash")
const constHash = Metho.add(
[Number.prototype, String.prototype],
() => nonHash,
const multiFunc = function (t) {
return this[Metho.data] + ' --- ' + t
}
const multi = Metho.add(
[Array.prototype, String.prototype],
multiFunc,
{ symbolName: "kumquat" },
)

expect(12345[constHash]).toBe(nonHash)
expect("this is a string"[constHash]).toBe(nonHash)
Array.prototype[Metho.data] = "array"
String.prototype[Metho.data] = "string"

expect("Jon"[multi(111)]).toBe("string --- 111")
expect([][multi(222)]).toBe("array --- 222")

expect(JSON.stringify(multi.targets)).toEqual(JSON.stringify([[], ""]))
})

describe("add", () => {
Expand All @@ -31,7 +43,7 @@ describe("metho library", () => {
expect(65534[asHex]).toBe("fffe")
})

it("should augment a single prototype (outer)", () => {
it("should augment a single prototype (outerSyntax: false)", () => {
const chunk = Metho.add(
String.prototype,
function(length) {
Expand All @@ -43,7 +55,7 @@ describe("metho library", () => {
.toEqual(["He", "ll", "o ", "Wo", "rl", "d!"])
})

it("should augment a single prototype (outer)", () => {
it("should augment a single prototype (outerSyntax: true)", () => {
const chunk = Metho.add(
String.prototype,
function(length) {
Expand All @@ -55,6 +67,17 @@ describe("metho library", () => {
expect("Hello World!"[chunk](2))
.toEqual(["He", "ll", "o ", "Wo", "rl", "d!"])
})

it("should use the provided symbolName", () => {
const symbolName = "octal"
const oct = Metho.add(
Number.prototype,
function oct() { return this.toString(8) },
{ symbolName },
)

expect(oct.toString()).toBe(Symbol(symbolName).toString())
})
})

describe("addSimple", () => {
Expand Down

0 comments on commit cab6262

Please sign in to comment.