Public
Edited
Nov 10, 2024
1 fork
Importers
19 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
suite.test("sync pass", () => expect(true).toBe(true))
Insert cell
Insert cell
suite.test("sync fail", () => expect(true).toBe(false))
Insert cell
suite.test("throw exception", () => {
console.log("Run: Throws exception")
expect(() => {
throw new Error("Expected exception");
}).toThrow();
})
Insert cell
suite.test("asyncORIG - original function", async () => {
console.log("Run: async function")
await new Promise(resolve => setTimeout(resolve, 500));
return "foo2"
})
Insert cell
Insert cell
Insert cell
suite.test("async0 - should fail, no resolve", async () => {
console.log("Run: async function")
// await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise( resolve => {});
})
Insert cell
suite.test("async1 check returned data", async () => {
await new Promise(resolve => setTimeout(()=>resolve("foo"), 1000))
.then(data => {
expect(data).toBe("foo");
})
})
Insert cell
Insert cell
suite.test("async2 function hanging example, should fail", done => {
});

// based on "unresolved" example at https://jestjs.io/docs/en/asynchronous

Insert cell
Insert cell
suite.test("done arg is an error", done => {
done(new Error("Not an error really"));
})

// based on "unresolved" example at https://jestjs.io/docs/en/asynchronous
Insert cell
Insert cell
Insert cell
suite.test("async4: the data is peanut butter", () => {
const fetchData = () => new Promise((resolve) => resolve("peanut butter"));
return fetchData().then((data) => {
expect(data).toBe("peanut butter");
});
})

// adapted example from https://jestjs.io/docs/en/asynchronous
// not using await
Insert cell
Insert cell
suite.viewofResults.value
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//import { customJsonFormatter } from "@tomlarkworthy/highlight"
Insert cell
//import { footer } from "@tomlarkworthy/footer"
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more