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

Update stubs-spies-and-clocks.md #489

Merged
merged 2 commits into from
Apr 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions source/guides/guides/stubs-spies-and-clocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ You generally stub a function when it has side effects you are trying to control
- You have a function that accepts a callback, and want to invoke the callback.
- Your function returns a `Promise`, and you want to automatically resolve or reject it.
- You have a function that wraps `window.location` and don't want your application to be navigated.
- You're trying to test your applications "failure path" by forcing things to fail.
- You're trying to test your applications "happy path" by forcing things to pass.
- You're trying to test your application's "failure path" by forcing things to fail.
- You're trying to test your application's "happy path" by forcing things to pass.
- You want to "trick" your application into thinking it's logged in or logged out.
- You're using `oauth` and want to stub login methods.

Expand All @@ -81,7 +81,7 @@ You generally stub a function when it has side effects you are trying to control

## Spies

A spy gives you the ability to "spy" on a function, by being able to capture and then assert that the function was calling with the right arguments, or that the function was called a certain number of times, or even what the return value or context the function was called with.
A spy gives you the ability to "spy" on a function, by being able to capture and then assert that the function was called with the right arguments, or that the function was called a certain number of times, or even what the return value was, or what context the function was called with.

A spy does **not** modify the behavior of the function - it is left perfectly intact. A spy is most useful when you are testing the contract between multiple functions and you don't care about the side effects the real function may create (if any).

Expand All @@ -95,15 +95,15 @@ cy.spy(obj, "method")

## Clock

There are situations when it is useful to control your applications `date` and `time` in order to force its behavior or avoid slow tests.
There are situations when it is useful to control your application's `date` and `time` in order to force its behavior or avoid slow tests.

{% url `cy.clock()` clock %} gives you the ability to control:

- `Date`
- `setTimeout`
- `setInterval`

***Common Scenarios:***
***Common Scenarios***

- You're polling something in your application with `setInterval` and want to control that.
- You have **throttled** or **debounced** functions which you want to control.
Expand Down Expand Up @@ -182,10 +182,10 @@ Beyond just integrating these tools together we have also extended and improved

- We replaced Sinon's argument stringifier for a much less noisy, more performant, custom version.
- We improved the `sinon-chai` assertion output by changing what displays during a passing vs failing test.
- We've added aliasing support to `stub` and `spy` API's.
- We added aliasing support to `stub` and `spy` API's.
- We automatically restore and teardown `stub`, `spy`, and `clock` between tests.

We also integrated all of these API's directly into the Command Log so you can visually see what's happening in your application.
We also integrated all of these API's directly into the Command Log, so you can visually see what's happening in your application.

***We visually indicate when:***

Expand All @@ -197,11 +197,11 @@ When you use aliasing with the {% url `.as()` as %} command, we also correlate t

When stubs are created by calling the method `.withArgs(...)` we also visually link these together.

When you click on a stub or spy we also output **incredibly** helpful debugging information.
When you click on a stub or spy, we also output **incredibly** helpful debugging information.

***For instance we automatically display:***

- The call count (and total number of calls)
- The arguments without transforming them (they are the real arguments)
- The arguments, without transforming them (they are the real arguments)
- The return value of the function
- The context the function was invoked with