Created
January 2, 2019 17:38
-
-
Save RobinCsl/eba9403481c231c708b90aa13053bc7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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