Created
May 29, 2019 09:53
-
-
Save lfac-pt/7df008da338cace20389f9e2b4193cce to your computer and use it in GitHub Desktop.
Example 5 of my JavaScript and React unit tests basics
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
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