Skip to content

Instantly share code, notes, and snippets.

@lfac-pt
Created May 29, 2019 09:53
Show Gist options
  • Save lfac-pt/7df008da338cace20389f9e2b4193cce to your computer and use it in GitHub Desktop.
Save lfac-pt/7df008da338cace20389f9e2b4193cce to your computer and use it in GitHub Desktop.
Example 5 of my JavaScript and React unit tests basics
describe("searchPosts", () => {
test("filters the results according to the input search", () => {
const loadPostsBackup = User.prototype.loadPosts;
User.prototype.loadPosts = () => [{id: 1, title: "bob"}, {id: 2, title: "alice"}];
const mockUser = new User({ username: "bob" });
expect(mockUser.searchPosts("bob")).toEqual([{id: 1, title: "bob"}]);
User.prototype.loadPosts = loadPostsBackup;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment