UNPKG

telvis

Version:

Typescript/Javascript safe-navigation operator, also known as Elvis operator

24 lines (19 loc) 624 B
import { suite, test, slow, timeout, skip, only } from "mocha-typescript" import '../src/telvis' interface A { b ?: B } interface B { c ?: C } interface C { hello ?: string } @suite class Telvis { @test "Find a defined property"() { let a: A = { "b": { "c" : { hello: "world" }}} if(a.path("b", "c", "hello") !== "world") { throw new Error("World was not hello") } } @test "Safely get an undefined property" () { let a: A = { "b" : {} } if(a.path("b", "c", "hello") !== undefined) { throw new Error("World was not undefined") } } }