Created
May 29, 2019 09:50
-
-
Save lfac-pt/e36616e95db6483fb8bb776521cd9064 to your computer and use it in GitHub Desktop.
Example 3 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("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