-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
37 lines (33 loc) · 1.08 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const proxyquire = require('proxyquire');
const Spy = require('jasmine-spy');
const index = require('./index');
const JWT = require('./lib/jwt');
describe('module', () => {
it('should expose jwt() method', () => {
expect(index).toEqual(jasmine.any(Function));
});
it('should expose the JWT class', () => {
expect(index.JWT).toEqual(JWT);
});
describe('jwt()', () => {
let fakeIndex, JWTStub, options, middleware, constructorCount;
beforeEach(() => {
constructorCount = 0;
options = {'foo': 'bar'};
JWTStub = class {
constructor(opt) {
expect(opt).toEqual(options);
constructorCount++;
}
};
middleware = Spy.resolve();
JWTStub.prototype.getMiddleware = Spy.returnValue(middleware);
fakeIndex = proxyquire('./index', {'./lib/jwt': JWTStub});
});
it('should create JWT instance with the options and return its middleware', () => {
const actualMiddleware = fakeIndex(options);
expect(constructorCount).toEqual(1);
expect(actualMiddleware).toEqual(middleware);
});
});
});