Skip to content

fatrixienicolieopetina/practice-jest-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PROJECT: TESTING PRACTICE Using Jest

🤔 WIL/Thoughts

  1. TDD's main idea is simply start working working on code by writing automated tests BEFORE writing the code that is being tested.
  2. There are many test-running systems in Javascript: Jasmine, Jest, Tape, Mocha. They have their special features but the syntax is very similar.
  3. Writing tests is less about the syntax but more on the TDD philosophy, so I tried internalizing the concepts using Jest. Main goal is to know the why and what to test.

📌 Notes from The Magic of Testing

  1. Why most devs hate tests? They are slow and fragile and expensive (time).
  2. It is perfectly valid to delete some tests.
  3. Unit Test Goals: They must be thorough (we want them to prove logically and completely that the single object under test is behaving correctly) and stable (we dont want to break the test everytime the implementation detail is changed 😟), fast and few (write tests for the most parsimonious expression [mmmmmm 🤔]).
  4. The object under test have three origin of messages : Incoming - messages to the object from outside, Self - messages sent by the object under test to itself and Outgoing - messsages sent by the object to the outside.
  5. There are two types of messages : query and command. Queries return something or changes nothing. Command types return nothing but changes something.
  6. Grid of Test Rules
Message Type Query Command
Incoming Assert result
Test incoming query messages by making assertions about what they send back.
Test the interface and not the implementation.
Test incoming command messages by making assertions about direct public side effects.
DRY it out. Receiver of incoming message has sole responsibility for asserting the result of direct public side effects.
Sent to Self Ignore: Do not test private methods. Ignore: Do not test private methods.
Outgoing Ignore. The receiver of an incoming query is solely responsible for assertions that involve state.
If a message has no visible side effects, the sender should not test it
Expect to send outgoing command messages using mocks
  1. Do not test private methods. But break this rule if it saves money during development.
  2. A mock is a test double, it plays the role of some object in your real app. Ensure test double stays in sync with the API.
  3. Trust collaborators that they will do the right thing. Insist on simplicity.
  4. Getting better at testing takes time and practice.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published