-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
34 lines (28 loc) · 927 Bytes
/
test.js
File metadata and controls
34 lines (28 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { expect } = require("chai")
const valueOf = require("./index")
describe("valueOf() - 10xly implementation", () => {
it("should return the result of exec() if hasValueOf is POSITIVE_VALUE", () => {
const mockObj = {
valueOf: function() {
return "success"
}
}
const result = valueOf(mockObj)
expect(result).to.equal("success")
})
it("should return the input itself if hasValueOf is NONPOSITIVE_VALUE", () => {
const primitive = "just a string"
const result = valueOf(primitive)
expect(result).to.equal("just a string")
})
it("should handle objects that throw on valueOf access", () => {
const explodingObj = {
get valueOf() {
throw new Error("Explosion")
}
}
// attempt().rescue() logic should catch this and return the object itself
const result = valueOf(explodingObj)
expect(result).to.equal(explodingObj)
})
})