- input & outputs
- methods on classes
- data manipulation
- test environment is the terminal
- DOM manipulation
- interactions that rely on the browser
- "spy" on methods to ensure they were called
- how many times the method was called
- arguments it was called with
Spies is a package that chai puts out. Can be installed with NPM by setting it as a dev dependency by doing this in terminal
npm install chai-spies --save-dev
const array = [1, 2, 3];
chai.spy.on(array, 'push');
// or multiple spies
chai.spy.on(array, ['push', 'pop']);
chai.spy.on(objectToSpyOn, methods, behaviorOfOurMethods)
Chai Spies Audit:
- What do we use spies for?
To simulate a browser environment in the terminal for use in testing as the terminal doesn't recognize certain tech.
-
What's the difference between spies and mocks? Mocks make a false version of a tech like localStorage for testing purposes while spies uses an 'empty' version of these things with no real functionality. It rather just tests that it is there.
-
Briefly decrsibe the process for setting up a spy You have to link it in the page with a require and showing that it is an extension of chai. Then in the tests, you must specify the module you are simulating and any methods you may want to run from it.
-
How many mandatory arguments does spy take? 2, 3 optional
-
What arguments does chai.spy.on() take? The module, and any methods, and something else I forget.
- install shai-spies (dev-dep)
- require chai spies
- initialize chai to use spies ( chai.use(spies))
- make object to spy on (prevent ref errors)
- chai.spy.on(...)