Tests
import { getDnsServers } from "../src/dns";import { getTldInfo } from "../src/index";import { mockDomainAvailability } from "../src/mockDomainAvailability";import { fetchHnsDomainData } from "../src/fetch";describe("getDnsServers", () => { it("should return the correct DNS servers for ICANN", () => { const result = getDnsServers("ICANN"); expect(result).toEqual(["0.0.0.0", "1.1.1.1"]); }); it("should return the correct DNS servers for HNS", () => { const result = getDnsServers("HNS"); expect(result).toEqual(["103.196.38.38", "103.196.38.39"]); });});describe("getTldInfo", () => { it("should return the correct TLDs for HNS", () => { const result = getTldInfo("HNS"); expect(result).toBeInstanceOf(Array); }); it("should return the correct TLDs for ICANN", () => { const result = getTldInfo("ICANN"); expect(result).toBeInstanceOf(Array); });});describe("mockDomainAvailability", () => { it("should return a boolean value", () => { const result = mockDomainAvailability("miguelgargallo"); expect(typeof result).toBe("boolean"); });});describe("fetchHnsDomainData", () => { it("should return the domain data and history", async () => { const result = await fetchHnsDomainData("miguelgargallo"); expect(result).toHaveProperty("ehnsfans"); expect(result).toHaveProperty("niami"); expect(result.ehnsfans).toHaveProperty("domain"); expect(result.ehnsfans).toHaveProperty("history"); expect(result.niami).toHaveProperty("domain"); expect(result.niami).toHaveProperty("unicode"); expect(result.niami).toHaveProperty("hsd"); expect(result.niami).toHaveProperty("txs"); }); it("should throw an error for an invalid domain", async () => { await expect(fetchHnsDomainData("invalid-domain")).rejects.toThrow( "Error fetching HNS domain data" ); });});
key | value |
---|---|
getDnsServers | Function that returns an array of DNS servers of the specified type. |
getTldInfo | Function that returns an array of TLDs of the specified type. |
mockDomainAvailability | Function that returns a random boolean value to simulate domain availability. |
fetchHnsDomainData | Function that returns an object containing data related to an HNS domain. |
describe | Function to define a test suite. |
it | Function to define a test case. |
expect | Function to assert the expected result. |
This file contains the test suites and test cases for various functions in the project, such as getDnsServers
, getTldInfo
, mockDomainAvailability
, and fetchHnsDomainData
.
The test suites are organized using the describe
function, and individual test cases are defined using the it
function. The expect
function is used to assert the expected results of each test case.
The test cases cover the following scenarios:
getDnsServers
: Return the correct DNS servers for ICANN. Return the correct DNS servers for HNS.getTldInfo
: Return the correct TLDs for HNS. Return the correct TLDs for ICANN.mockDomainAvailability
: Return a boolean value.fetchHnsDomainData
: Return the domain data and history for a valid HNS domain. Throw an error for an invalid HNS domain.