diff --git a/expectjs.md b/expectjs.md index bbdb6f718..631ea0322 100644 --- a/expectjs.md +++ b/expectjs.md @@ -2,9 +2,34 @@ title: expect.js category: JavaScript libraries layout: 2017/sheet +updated: 2017-09-02 +weight: -1 --- -### Expectations +### Using + +``` +npm install --save-dev expect +``` +{: .-setup} + +```js +// using ES6 modules +import expect, { createSpy, spyOn, isSpy } from 'expect' +``` + +```js +// using CommonJS modules +var expect = require('expect') +var createSpy = expect.createSpy +var spyOn = expect.spyOn +var isSpy = expect.isSpy +``` + +Expect is a library for assertions in tests. +See: [mjackson/expect](https://github.com/mjackson/expect) + +### Assertions ```js expect(x).toBe(y) @@ -41,18 +66,27 @@ Assertions can be chained. ### Spies +```js +const video = { + play: function () { ··· } +} +``` +{: .-setup} + ```js spy = expect.spyOn(video, 'play') ``` ```js -spy = expect.spyOn(...) - .andCallThrough() /* pass through */ +spy = expect.spyOn(···) + .andCallThrough() // pass through .andCall(fn) .andThrow(exception) .andReturn(value) ``` +### Assertions on spies + ```js expect(spy.calls.length).toEqual(1) expect(spy.calls[0].context).toBe(video)