UNPKG

1.57 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Chai assert library
5 * @external chai
6 * @see {@link http://chaijs.com/}
7 */
8
9 /**
10 * Chai promise assert library
11 * @external chai-as-promised
12 * @see {@link https://github.com/domenic/chai-as-promised}
13 */
14
15/**
16 * Standalone and test framework agnostic JavaScript test spies, stubs and mocks
17 * @external sinon
18 * @see {@link https://github.com/sinonjs/sinon}
19 */
20
21/**
22 * Tap testing library
23 * @external tap
24 * @see {@link http://www.node-tap.org/}
25 */
26
27const chaiLibrary = require('chai');
28const chaiAsPromisedLib = require('chai-as-promised');
29const sinonLibrary = require('sinon');
30const sinonTest = require('sinon-test');
31const tap = require('tap');
32
33sinonLibrary.test = sinonTest.configureTest(sinonLibrary);
34sinonLibrary.testCase = sinonTest.configureTestCase(sinonLibrary);
35
36/**
37 * Sinon stubs/mocks/spies etc.
38 * @returns {external:sinon} sinon object for mocking/stubing/spying
39 */
40const getSinon = () => sinonLibrary;
41
42/**
43 * Sinon sandbox
44 * @returns {external:sinon.sandbox} sinon sandbox object for mocking/stubing/spying
45 */
46const getSinonSandbox = () => sinonLibrary.sandbox.create();
47/**
48 * Chai with promise support library
49 * @returns {external:chai-as-promised} chai with support library
50 */
51const getChai = () => {
52 chaiLibrary.use(chaiAsPromisedLib);
53 chaiLibrary.should();
54 return chaiLibrary;
55};
56
57/**
58 * Tap testing library
59 * @returns {external:tap} tap testing library
60 */
61const getTap = () => tap;
62
63module.exports = {
64 getExpect: () => getChai().expect,
65 getChai,
66 getSinon,
67 getSinonSandbox,
68 getTap,
69};