Skip to content

Instantly share code, notes, and snippets.

@RobinCsl
Created January 2, 2019 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinCsl/eba9403481c231c708b90aa13053bc7d to your computer and use it in GitHub Desktop.
Save RobinCsl/eba9403481c231c708b90aa13053bc7d to your computer and use it in GitHub Desktop.
const fc = require("fast-check");
const capitalize = text => (text ? text[0].toUpperCase() + text.slice(1) : "");
/* works fine */
it("returns the correct string", () => {
fc.assert(
fc.property(fc.string(), text => {
if (text) {
const capitalizedText = capitalize(text);
expect(text[0].toUpperCase()).toBe(capitalizedText[0]);
expect(capitalizedText[0].toUpperCase()).toBe(capitalizedText[0]);
expect(capitalizedText.slice(1)).toBe(text.slice(1));
}
})
);
expect(capitalize("kiwi.com")).toBe("Kiwi.com");
expect(capitalize(null)).toBe("");
expect(capitalize("")).toBe("");
});
/* `text` being null/undefined will break the test */
it("returns the correct string", () => {
fc.assert(
fc.property(fc.string(), text => {
const capitalizedText = capitalize(text);
expect(text[0].toUpperCase()).toBe(capitalizedText[0]);
expect(capitalizedText[0].toUpperCase()).toBe(capitalizedText[0]);
expect(capitalizedText.slice(1)).toBe(text.slice(1));
})
);
expect(capitalize("kiwi.com")).toBe("Kiwi.com");
expect(capitalize(null)).toBe("");
expect(capitalize("")).toBe("");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment