Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing with Mocks #67

Open
mabelleeyanhwa opened this issue Dec 2, 2019 · 0 comments
Open

Testing with Mocks #67

mabelleeyanhwa opened this issue Dec 2, 2019 · 0 comments

Comments

@mabelleeyanhwa
Copy link
Contributor

code-along template: https://github.com/thoughtworks-jumpstart/learn-mocking-and-stubbing

lesson outline:

  • write on board: jest.fn(factory), jest.mock(path, factory)
  • what are mocks
    • Mocking is a technique to isolate test subjects by replacing dependencies with objects that you can control. The goal for mocking is to replace something we don’t control with something we do
  • when to mock
  • how to create mocks with jest.fn() and jest.mock()
  • assertions which we can use on mock functions
  • demo
    • fetch
    • payment gateway
    • 2 classes

jest gives us many ways to define a mock. see https://medium.com/@rickhanlonii/understanding-jest-mocks-f0046c68e53c for a comparison (note. it's using ES6 import syntax, so you have to map it to your CommonJS import/export syntax)

recap:

  • benefits of mocking
    • simplify testing (e.g. new Cat(brain, tail, coatOfFur, owner))
    • prevent expensive operations (e.g. fetch or actual payments)
    • simulate all edge cases in a class/function
    • remove dependencies (on data, network requests, other classes, etc)
  • terms
    • mocks, stubs, dummies, spies
@mabelleeyanhwa mabelleeyanhwa created this issue from a note in Program Outline (Week 2 - JavaScript + React) Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Program Outline
Week 2 - JavaScript: Jan 13
Development

No branches or pull requests

1 participant