Skip to content

Instantly share code, notes, and snippets.

@lfac-pt
Last active May 29, 2019 09:55
Show Gist options
  • Save lfac-pt/41a7ee8d06a737e49ed868e395b6bf80 to your computer and use it in GitHub Desktop.
Save lfac-pt/41a7ee8d06a737e49ed868e395b6bf80 to your computer and use it in GitHub Desktop.
Example 2 of my JavaScript and React unit tests basics
describe("deletePost", () => {
test("calls the REST API method to delete the post, but only if the user is logged in", () => {
const mockUser = new User({ username: "bob" });
mockUser.ajax = spy();
mockUser.login();
mockUser.deletePost();
expect(mockUser.ajax).to.haveCallCount(1);
mockUser.logout();
mockUser.deletePost();
expect(mockUser.ajax).to.haveCallCount(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment