3 category: JavaScript libraries
12 npm install --save-dev expect
18 import expect, { createSpy, spyOn, isSpy } from 'expect'
22 // using CommonJS modules
23 var expect = require('expect')
24 var createSpy = expect.createSpy
25 var spyOn = expect.spyOn
26 var isSpy = expect.isSpy
29 Expect is a library for assertions in tests.
30 See: [mjackson/expect](https://github.com/mjackson/expect)
39 .toExist() // aka: toBeTruthy()
40 .toNotExist() // aka: toBeFalsy()
46 .toBeLessThanOrEqualTo(n)
47 .toBeGreaterThanOrEqualTo(n)
48 .toInclude(val) // aka: toContain(val)
54 Also: `toNotBe`, `toNotEqual`, etc for negatives.
56 ### Chaining assertions
65 Assertions can be chained.
71 play: function () { ··· }
77 spy = expect.spyOn(video, 'play')
81 spy = expect.spyOn(···)
82 .andCallThrough() // pass through
88 ### Assertions on spies
91 expect(spy.calls.length).toEqual(1)
92 expect(spy.calls[0].context).toBe(video)
93 expect(spy.calls[0].arguments).toEqual([ 'some', 'args' ])
94 expect(spy.getLastCall().arguments).toEqual(...)
98 expect(spy).toHaveBeenCalled()
99 expect(spy).toHaveBeenCalledWith('some', 'args')
104 - <https://www.npmjs.com/package/expect>
105 - <https://github.com/mjackson/expect>