Skip to content

Instantly share code, notes, and snippets.

@lfac-pt
Created May 29, 2019 09:50
Show Gist options
  • Save lfac-pt/e36616e95db6483fb8bb776521cd9064 to your computer and use it in GitHub Desktop.
Save lfac-pt/e36616e95db6483fb8bb776521cd9064 to your computer and use it in GitHub Desktop.
Example 3 of my JavaScript and React unit tests basics
describe("deletePost", () => {
let mockUser;
beforeEach(() => {
mockUser = new User({ username: "bob" });
mockUser.ajax = spy();
});
test("calls the REST API method to delete the post", () => {
mockUser.login();
mockUser.deletePost();
expect(mockUser.ajax).to.haveCallCount(1);
});
test("doesn't call the REST API method to delete the post if the user is logged out", () => {
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