Published
Edited
Oct 16, 2020
1 fork
Importers
3 stars
Unit testing with Jest expect()
Insert cell
Insert cell
Insert cell
Insert cell
test(() => {
expect(2 + 2).toEqual(4)
})
Insert cell
test("arithmetic", () => {
expect(2 + 2).toEqual(4)
})
Insert cell
test(() => {
expect(2 + 2).toEqual(5)
})
Insert cell
test("arithmetic", () => {
expect(2 + 2).toEqual(5)
})
Insert cell
test.skip(() => {
expect(2 + 2).toEqual(4)
})
Insert cell
test.skip("arithmetic", () => {
expect(2 + 2).toEqual(4)
})
Insert cell
Insert cell
testcase({
input: "foobar",
test: input => input.length,
output: 6,
})
Insert cell
testcase("string length", {
input: "foobar",
test: input => input.length,
output: 6,
})
Insert cell
testcase({
input: "foobar",
test: input => input.length,
output: 99,
})
Insert cell
testcase("string length", {
input: "foobar",
test: input => input.length,
output: 99,
})
Insert cell
testcase.skip({
input: "foobar",
test: input => input.length,
output: 6,
})
Insert cell
testcase.skip("string length", {
input: "foobar",
test: input => input.length,
output: 6,
})
Insert cell
Insert cell
Insert cell
expect = require(`jest-expect-standalone@${jestExpectStandaloneVersion}/dist/expect.min.js`).catch(() => window.expect)
Insert cell
test = {
const withMessage = (title, color) =>
html`<div style="font: var(--mono_fonts); color: ${color}; padding: 6px 0;">${title}</div>`
const test = (...args) => {
const [action, title] = args.reverse()
action()
return withMessage(`Success: ${title || "test passed"}`, "green")
}
test.skip = (...args) => {
const [action, title] = args.reverse()
return withMessage(`Skipped: ${title || "test skipped"}`, "darkorange")
}
return test
}
Insert cell
testcase = {
const withMessage = (title, color) =>
html`<div style="font: var(--mono_fonts); color: ${color}; padding: 6px 0;">${title}</div>`
const test = (...args) => {
const [fixture, title] = args.reverse()
const actual = fixture.test ? fixture.test(fixture.input) : fixture.input
const expected = fixture.output
expect(actual).toEqual(expected)
return withMessage(`Success: ${title || "test passed"}`, "green")
}
test.skip = (...args) => {
const [fixture, title] = args.reverse()
return withMessage(`Skipped: ${title || "test skipped"}`, "darkorange")
}
return test
}
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