Skip to content

Commit bf4ee7b

Browse files
committed
add back the unit tests from index.html
1 parent 0c4ea84 commit bf4ee7b

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

metho.test.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import * as Metho from './metho.js'
22

33
describe("metho library", () => {
4+
it("should export a data Symbol", () => {
5+
expect(Metho.data).not.toBeUndefined()
6+
})
7+
48
it("should augment multiple prototypes", () => {
5-
const nonHash = Symbol("No hash")
6-
const constHash = Metho.add(
7-
[Number.prototype, String.prototype],
8-
() => nonHash,
9+
const multiFunc = function (t) {
10+
return this[Metho.data] + ' --- ' + t
11+
}
12+
const multi = Metho.add(
13+
[Array.prototype, String.prototype],
14+
multiFunc,
15+
{ symbolName: "kumquat" },
916
)
1017

11-
expect(12345[constHash]).toBe(nonHash)
12-
expect("this is a string"[constHash]).toBe(nonHash)
18+
Array.prototype[Metho.data] = "array"
19+
String.prototype[Metho.data] = "string"
20+
21+
expect("Jon"[multi(111)]).toBe("string --- 111")
22+
expect([][multi(222)]).toBe("array --- 222")
23+
24+
expect(multi.targets.map((target) => target.constructor.name).sort())
25+
.toEqual(["Array", "String"])
1326
})
1427

1528
describe("add", () => {
@@ -31,7 +44,7 @@ describe("metho library", () => {
3144
expect(65534[asHex]).toBe("fffe")
3245
})
3346

34-
it("should augment a single prototype (outer)", () => {
47+
it("should augment a single prototype (outerSyntax: false)", () => {
3548
const chunk = Metho.add(
3649
String.prototype,
3750
function(length) {
@@ -43,7 +56,7 @@ describe("metho library", () => {
4356
.toEqual(["He", "ll", "o ", "Wo", "rl", "d!"])
4457
})
4558

46-
it("should augment a single prototype (outer)", () => {
59+
it("should augment a single prototype (outerSyntax: true)", () => {
4760
const chunk = Metho.add(
4861
String.prototype,
4962
function(length) {
@@ -55,6 +68,17 @@ describe("metho library", () => {
5568
expect("Hello World!"[chunk](2))
5669
.toEqual(["He", "ll", "o ", "Wo", "rl", "d!"])
5770
})
71+
72+
it("should use the provided symbolName", () => {
73+
const symbolName = "octal"
74+
const oct = Metho.add(
75+
Number.prototype,
76+
function oct() { return this.toString(8) },
77+
{ symbolName },
78+
)
79+
80+
expect(oct.toString()).toBe(Symbol(symbolName).toString())
81+
})
5882
})
5983

6084
describe("addSimple", () => {

0 commit comments

Comments
 (0)